use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncDeactivateComponent.
/**
* Deactivate component, issue deactivate reeust to container (or other manager).
* @param componentInfo info about component to be deactivated.
*/
private void internalNoSyncDeactivateComponent(ComponentInfo componentInfo) throws Throwable {
// unbind from remote directory
//unbind(convertToHiearachical(componentInfo.getName()), "O");
int handle = componentInfo.getHandle() & HANDLE_MASK;
int owners = componentInfo.getClients().size();
try {
//
// get container/remote manager
//
String name = componentInfo.getName();
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
if (isOtherDomainComponent) {
Manager remoteManager = null;
// @todo MF do the login?
try {
String domainName = CURLHelper.createURI(name).getAuthority();
remoteManager = getManagerForDomain(domainName);
if (remoteManager == null)
throw new CoreException("Failed to obtain manager for domain '" + domainName + "'.");
} catch (Throwable th) {
logger.log(Level.WARNING, "Failed to obtain non-local manager required by component '" + name + "'.", th);
throw th;
}
// release component
try {
URI curlName = CURLHelper.createURI(name);
// @todo MF tmp (handle)
remoteManager.releaseComponent(INTERDOMAIN_MANAGER_HANDLE, curlName);
} catch (Throwable th) {
logger.log(Level.WARNING, "Failed to release component '" + componentInfo.getName() + "' on remote manager.'", th);
throw th;
}
} else {
//
// 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) {
// remove component from container component list
synchronized (containerInfo.getComponents()) {
// !!! ACID
if (containerInfo.getComponents().contains(componentInfo.getHandle()))
executeCommand(new ContainerInfoCommandComponentRemove(containerInfo.getHandle() & HANDLE_MASK, componentInfo.getHandle()));
//containerInfo.getComponents().remove(componentInfo.getHandle());
}
// we allow this (since releasing components is part of container shutdown procedure)
//checkContainerState(containerInfo);
container = containerInfo.getContainer();
}
// required container is not logged in
if (container == null) {
// then simply do not do the deactivation
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.");
}
}
if (container != null) {
// log info
logger.log(Level.INFO, "Deactivating component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") on container '" + containerInfo.getName() + "'.");
// destruct
try {
componentInfo.getComponent().destruct();
} catch (Throwable ex) {
RemoteException re = new RemoteException("Failed to destruct component '" + componentInfo.getName() + "', exception caught when invoking 'destruct()' method.", ex);
logger.log(Level.SEVERE, re.getMessage(), re);
throw ex;
}
long deactivationTime = 0;
// deactivate component in anycase
try {
container.deactivate_component(componentInfo.getHandle());
deactivationTime = System.currentTimeMillis();
} catch (AcsJException aex) {
logger.log(Level.SEVERE, aex.getMessage(), aex);
throw aex;
} catch (Throwable ex) {
RemoteException re = new RemoteException("Failed to deactivate component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") on container '" + containerInfo.getName() + "'.", ex);
logger.log(Level.SEVERE, re.getMessage(), re);
throw ex;
}
// notify administrators about deactivation, but not if failed
if (deactivationTime != 0)
notifyComponentDeactivated(componentInfo.getHandle(), deactivationTime);
// shutdown container if required (and necessary)
conditionalShutdownContainer(containerInfo);
}
}
} finally {
if (owners == 0) {
// deallocate Component
componentsLock.lock();
try {
executeCommand(new ComponentCommandDeallocate(handle, componentInfo.getHandle(), WhyUnloadedReason.REMOVED));
//components.deallocate(handle);
} finally {
componentsLock.unlock();
}
}
}
// log info
logger.log(Level.INFO, "Component '" + componentInfo.getName() + "' (" + HandleHelper.toString(componentInfo.getHandle()) + ") deactivated.");
// release all subcomponents (just like client logoff)
// component should have already done this by itself, but take care of clean cleanup
// what about that: if subcomponent becomes unavailable, does component also becomes?!
// no, it is notified and it handles situation by its own way (e.g. changes component state).
// Just like it already handles activation (manager does not care for dependecy trees).
int[] subcomponents = null;
// no not hold the lock
synchronized (componentInfo.getComponents()) {
if (componentInfo.getComponents().size() > 0) {
IntArray toCleanupList = new IntArray();
IntArray comps = componentInfo.getComponents();
for (int i = 0; i < comps.size(); i++) if (components.isAllocated(comps.get(i) & HANDLE_MASK))
toCleanupList.add(comps.get(i));
if (toCleanupList.size() > 0)
subcomponents = toCleanupList.toArray();
}
//subcomponents = componentInfo.getComponents().toArray();
}
if (subcomponents != null && subcomponents.length > 0)
new ReleaseComponentTask(componentInfo.getHandle(), subcomponents).run();
// make unavailable (deactivation was forced)
if (owners > 0)
makeUnavailable(componentInfo);
}
use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ContainerCommandUpdate method execute.
/**
* @see Command#execute(PrevalentSystem)
*/
public Serializable execute(PrevalentSystem system) throws Exception {
ContainerInfo containerInfo = (ContainerInfo) ((ManagerImpl) system).getContainers().get(handle);
containerInfo.setContainer(container);
return null;
}
use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ContainerInfoCommandComponentAdd method execute.
/**
* @see Command#execute(PrevalentSystem)
*/
public Serializable execute(PrevalentSystem system) throws Exception {
ContainerInfo containerInfo = (ContainerInfo) ((ManagerImpl) system).getContainers().get(handle);
containerInfo.getComponents().add(cobHandle);
return null;
}
use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ManagerImpl method internalNoSyncRequestComponent.
/**
* Internal method for requesting components (non sync).
* @param requestor requestor of the component.
* @param name name of component to be requested, non-<code>null</code>.
* @param type type of component to be requested; if <code>null</code> CDB will be queried.
* @param code code of component to be requested; if <code>null</code> CDB will be queried.
* @param containerName container name of component to be requested; if <code>null</code> CDB will be queried.
* @param status returned completion status of the request.
* @param activate <code>true</code> if component has to be activated
* @return componentInfo <code>ComponentInfo</code> of requested component.
*/
private ComponentInfo internalNoSyncRequestComponent(int requestor, String name, String type, String code, String containerName, int keepAliveTime, StatusHolder status, boolean activate) throws AcsJCannotGetComponentEx, AcsJComponentSpecIncompatibleWithActiveComponentEx {
AcsJCannotGetComponentEx bcex = null;
if (name == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Cannot activate component with NULL name.");
throw bcex;
}
if (status == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Component " + name + " has NULL status.");
throw bcex;
}
boolean isOtherDomainComponent = name.startsWith(CURL_URI_SCHEMA);
boolean isDynamicComponent = isOtherDomainComponent ? false : (type != null || code != null || containerName != null);
//
// check if component is already activated
//
int h;
// if true, component with handle h will be reactivated
boolean reactivate = false;
ComponentInfo componentInfo = null;
componentsLock.lock();
try {
h = components.first();
while (h != 0) {
componentInfo = (ComponentInfo) components.get(h);
if (componentInfo.getName().equals(name)) {
// check if component is unavailable
synchronized (unavailableComponents) {
if (unavailableComponents.containsKey(name)) {
// try to reactivate, possible component reallocation
reactivate = true;
}
}
// check for consistency
ContainerInfo containerInfo = getContainerInfo(componentInfo.getContainer());
if ((type != null && !componentInfo.getType().equals(type)) || (code != null && componentInfo.getCode() != null && !componentInfo.getCode().equals(code)) || (!reactivate && containerInfo != null && containerName != null && !containerInfo.getName().equals(containerName))) {
AcsJComponentSpecIncompatibleWithActiveComponentEx ciwace = new AcsJComponentSpecIncompatibleWithActiveComponentEx();
ciwace.setCURL(componentInfo.getName());
ciwace.setComponentType(componentInfo.getType());
ciwace.setComponentCode(componentInfo.getCode() != null ? componentInfo.getCode() : "<unknown>");
ciwace.setContainerName(containerInfo != null ? containerInfo.getName() : "<none>");
throw ciwace;
}
if (activate) {
// bail out and reactivate
if (reactivate)
break;
// add client/component as an owner (if requestor is not 'reactivation')
if (requestor != 0) {
// !!! ACID
if (!componentInfo.getClients().contains(requestor))
executeCommand(new ComponentCommandClientAdd(componentInfo.getHandle() & HANDLE_MASK, requestor));
//componentInfo.getClients().add(requestor);
}
// add component to client component list (if requestor is not manager or 'reactivation')
if (requestor != this.getHandle() && requestor != 0)
addComponentOwner(componentInfo.getHandle(), requestor);
// inform administrators about component request
notifyComponentRequested(new int[] { requestor }, new int[] { componentInfo.getHandle() }, System.currentTimeMillis());
// on complete system shutdown sort will be done anyway
if ((requestor & TYPE_MASK) == COMPONENT_MASK) {
ComponentInfo requestorComponentInfo = getComponentInfo(requestor);
if (requestorComponentInfo != null && requestorComponentInfo.getContainerName() != null && requestorComponentInfo.getContainerName().equals(componentInfo.getContainerName()))
topologySortManager.notifyTopologyChange(componentInfo.getContainer());
}
// return info
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return componentInfo;
} else {
if (reactivate)
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
else
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return componentInfo;
}
}
h = components.next(h);
}
} finally {
componentsLock.unlock();
}
// and do not touch CDB
if (reactivate && componentInfo.isDynamic()) {
if (componentInfo.getType() == null || componentInfo.getCode() == null || componentInfo.getDynamicContainerName() == null) {
// failed
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Failed to reactivate dynamic component '" + componentInfo + "'.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
} else {
// reread info
type = componentInfo.getType();
code = componentInfo.getCode();
containerName = componentInfo.getDynamicContainerName();
keepAliveTime = componentInfo.getKeepAliveTime();
}
} else // is CDB lookup needed
if (!isOtherDomainComponent && (type == null || code == null || containerName == null)) {
//
// read component info from CDB / remote directory lookup
//
DAOProxy dao = getComponentsDAOProxy();
if (dao == null || readStringCharacteristics(dao, name, true) == null) {
// component with this name does not exists,
// make a remote directory lookup
Object ref = lookup(name, null);
if (ref != null) {
// found
status.setStatus(ComponentStatus.COMPONENT_ACTIVATED);
return new ComponentInfo(0, name, null, null, new ServiceComponent(ref));
} else {
// not found
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Component " + name + " not found in CDB.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (code == null) {
code = readStringCharacteristics(dao, name + "/Code");
if (code == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Misconfigured CDB, there is no code of component '" + name + "' defined.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (type == null) {
type = readStringCharacteristics(dao, name + "/Type");
if (type == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Misconfigured CDB, there is no type of component '" + name + "' defined.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (containerName == null) {
containerName = readStringCharacteristics(dao, name + "/Container");
if (containerName == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Misconfigured CDB, there is no container of component '" + name + "' defined.");
status.setStatus(ComponentStatus.COMPONENT_DOES_NO_EXIST);
throw bcex;
}
}
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
// defaults to 0 == RELEASE_IMMEDIATELY
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
}
}
// we have keepAlive missing, try to get it
if (keepAliveTime == RELEASE_TIME_UNDEFINED) {
DAOProxy dao = getComponentsDAOProxy();
if (dao != null) {
// defaults to 0 == RELEASE_IMMEDIATELY
keepAliveTime = readLongCharacteristics(dao, name + "/KeepAliveTime", RELEASE_IMMEDIATELY, true);
} else {
// this is a case where all data for dynamic component is specified and there is not entry in CDB
keepAliveTime = RELEASE_IMMEDIATELY;
}
}
// read impl. language.
DAOProxy dao = getComponentsDAOProxy();
String componentImplLang = null;
if (dao != null) {
// silent read
componentImplLang = readStringCharacteristics(dao, name + "/ImplLang", true);
}
// if requestor did not request activation we are finished
if (!activate) {
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
return null;
}
/****************** component activation ******************/
//
// get container/remote manager
//
Container container = null;
ContainerInfo containerInfo = null;
Manager remoteManager = null;
if (isOtherDomainComponent) {
// @todo MF do the login?
try {
String domainName = CURLHelper.createURI(name).getAuthority();
remoteManager = getManagerForDomain(domainName);
if (remoteManager == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Failed to obtain manager for domain '" + domainName + "'.");
throw bcex;
}
} catch (Throwable th) {
bcex = new AcsJCannotGetComponentEx(th);
bcex.setReason("Failed to obtain non-local manager required by component '" + name + "'.'");
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
throw bcex;
}
} else {
// search for container by its name
containerInfo = getContainerInfo(containerName);
// try to start-up container
if (containerInfo == null)
containerInfo = startUpContainer(containerName);
// check state and get container
if (containerInfo != null) {
checkContainerShutdownState(containerInfo);
container = containerInfo.getContainer();
}
// required container is not logged in
if (container == null) {
bcex = new AcsJCannotGetComponentEx();
bcex.setReason("Container '" + containerName + "' required by component '" + name + "' is not logged in.");
status.setStatus(ComponentStatus.COMPONENT_NOT_ACTIVATED);
throw bcex;
}
}
// check container vs component ImplLang
ImplLang containerImplLang = containerInfo.getImplLang();
if (containerImplLang != null && containerImplLang != ImplLang.not_specified) {
if (componentImplLang != null && ImplLang.fromString(componentImplLang) != containerImplLang) {
AcsJCannotGetComponentEx af = new AcsJCannotGetComponentEx();
af.setReason("Component and container implementation language do not match (" + componentImplLang + " != " + containerImplLang.name() + ")");
throw af;
}
}
//
// get handle
//
// obtain handle
componentsLock.lock();
try {
// only preallocate (if necessary)
if (!reactivate) {
// !!! ACID 2
Integer objHandle = (Integer) executeCommand(new ComponentCommandPreallocate());
h = (objHandle == null) ? 0 : objHandle.intValue();
//h = components.preallocate();
}
// failed to obtain handle
if (h == 0) {
AcsJCannotGetComponentEx af = new AcsJCannotGetComponentEx();
af.setReason("Preallocation of new handle failed, too many registered components.");
throw af;
}
// create temporary ComponentInfo - to allow hierarchical components
if (!reactivate) {
ComponentInfo data = new ComponentInfo(h | COMPONENT_MASK, name, type, code, null);
data.setKeepAliveTime(keepAliveTime);
// !!! ACID
executeCommand(new ComponentCommandSet(h, data));
// add to pending activation list
synchronized (pendingActivations) {
pendingActivations.put(name, data);
}
// add component to client component list to allow dependency checks
if ((requestor & TYPE_MASK) == COMPONENT_MASK)
addComponentOwner(data.getHandle(), requestor);
}
} finally {
componentsLock.unlock();
}
//
// invoke get_component
//
componentInfo = null;
long executionId = 0;
long activationTime = 0;
boolean timeoutError = false;
if (isOtherDomainComponent) {
try {
URI curlName = CURLHelper.createURI(name);
StatusHolder statusHolder = new StatusHolder();
// @todo MF tmp (handle)
remoteManager.getComponent(INTERDOMAIN_MANAGER_HANDLE, curlName, true, statusHolder);
activationTime = System.currentTimeMillis();
if (statusHolder.getStatus() == ComponentStatus.COMPONENT_ACTIVATED) {
// local name to be used
String localName = curlName.getPath();
if (localName.charAt(0) == '/')
localName = localName.substring(1);
/// @TODO MF tmp (handle)
ComponentInfo[] infos = remoteManager.getComponentInfo(INTERDOMAIN_MANAGER_HANDLE, new int[0], localName, "*", true);
if (infos != null && infos.length == 1) {
componentInfo = infos[0];
// fix container name
componentInfo.setContainerName(CURL_URI_SCHEMA + curlName.getAuthority() + "/" + componentInfo.getContainerName());
}
//else
// throw new RemoteException("Failed to obtain component info for '"+name+"' from remote manager.");
}
//else
// throw new RemoteException("Failed to obtain component '"+name+"' from remote manager, status: " + statusHolder.getStatus() + ".");
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to obtain component '" + name + "' from remote manager.");
timeoutError = (ex instanceof TimeoutRemoteException);
}
} else {
//
// invoke get_component on container
//
// log info
String handleReadable = HandleHelper.toString(h | COMPONENT_MASK);
logger.log(Level.INFO, "Activating component '" + name + "' (" + handleReadable + ") on container '" + containerInfo.getName() + "'.");
boolean callSyncActivate = System.getProperties().containsKey(NAME_SYNC_ACTIVATE);
if (callSyncActivate) {
// sync
try {
executionId = generateExecutionId();
activationTime = System.currentTimeMillis();
componentInfo = container.activate_component(h | COMPONENT_MASK, executionId, name, code, type);
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to activate component '" + name + "' on container '" + containerName + "'.");
timeoutError = (ex instanceof TimeoutRemoteException);
}
} else {
// async
try {
executionId = generateExecutionId();
activationTime = System.currentTimeMillis();
ComponentInfoCompletionCallbackImpl callback = new ComponentInfoCompletionCallbackImpl(requestor, name, type, code, containerName, keepAliveTime, status, isOtherDomainComponent, isDynamicComponent, h, reactivate, container, containerInfo, executionId, activationTime);
addPendingContainerAsyncRequest(containerName, callback);
try {
container.activate_component_async(h | COMPONENT_MASK, executionId, name, code, type, callback);
} catch (Throwable t) {
// failed call, remove async request from the list
removePendingContainerAsyncRequest(containerName, callback);
throw t;
}
logger.log(AcsLogLevel.DELOUSE, "Asynchronous activation of component '" + name + "' (" + handleReadable + ") is running on container '" + containerInfo.getName() + "'.");
ComponentInfo ret;
try {
ret = callback.waitUntilActivated(getLockTimeout());
} catch (Throwable t) {
// failed call (most likely timeout), remove async request from the list
removePendingContainerAsyncRequest(containerName, callback);
throw t;
}
logger.log(AcsLogLevel.DELOUSE, "Asynchronous activation of component '" + name + "' (" + handleReadable + ") has finished on container '" + containerInfo.getName() + "'.");
return ret;
} catch (Throwable ex) {
bcex = new AcsJCannotGetComponentEx(ex);
bcex.setReason("Failed to activate component '" + name + "' on container '" + containerName + "'.");
throw bcex;
}
}
}
// call this immediately if bcex != null or sync call
return internalNoSyncRequestComponentPhase2(requestor, name, type, code, containerName, keepAliveTime, status, bcex, isOtherDomainComponent, isDynamicComponent, h, reactivate, componentInfo, container, containerInfo, executionId, activationTime, timeoutError);
}
use of com.cosylab.acs.maci.ContainerInfo in project ACS by ACS-Community.
the class ManagerImpl method getContainersInfo.
/**
* Returns array of currently logged containers.
* @return ContainerInfo[] array of currently logged containers
*/
private ContainerInfo[] getContainersInfo() {
// array of containers to be notified
ContainerInfo[] acts = null;
// generate array of containers to be notified
synchronized (containers) {
int len = containers.size();
// no containers to notify
if (len > 0) {
ArrayList<ContainerInfo> list = new ArrayList<ContainerInfo>();
int h = containers.first();
while (h != 0) {
ContainerInfo actInfo = (ContainerInfo) containers.get(h);
list.add(actInfo);
h = containers.next(h);
}
// copy to array
if (list.size() > 0) {
acts = new ContainerInfo[list.size()];
list.toArray(acts);
}
}
}
return acts;
}
Aggregations