use of com.cosylab.acs.maci.CoreException in project ACS by ACS-Community.
the class ManagerEngine method destroyManager.
/**
* Destroy the Manager.
*/
private void destroyManager() throws Exception {
logger.info("Destroying Manager.");
// firsty destroy Manager implementation (if necessary)
if (!manager.isShuttingDown()) {
try {
manager.shutdown(HandleConstants.MANAGER_MASK, 0);
} catch (Throwable ex) {
CoreException ce = new CoreException("Failed to destroy manager.", ex);
logger.log(Level.WARNING, "Failed to destroy manager.", ce);
}
}
// deactivate Manager
if (managerPOA != null && managerReference != null) {
managerPOA.deactivate_object(MANAGER_ID);
managerPOA = null;
}
// destroy CORBA service
if (corbaService != null)
corbaService.destroy();
// add rights to group in order to be able to start with '-n'
if (recoveryLocation != null)
FileHelper.setFileAttributes("g+w", recoveryLocation);
}
use of com.cosylab.acs.maci.CoreException 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.CoreException in project ACS by ACS-Community.
the class ManagerImpl method autoStartComponents.
/**
* Checks for autostart components that are to be hosed by autostart containers.
*/
private void autoStartComponents() {
// order is important, preserve it
LinkedHashSet<String> activationRequestsList = new LinkedHashSet<String>();
// get CDB access daos
DAOProxy dao = getManagerDAOProxy();
DAOProxy componentsDAO = getComponentsDAOProxy();
DAOProxy containersDAO = getContainersDAOProxy();
// no data
if (componentsDAO == null || containersDAO == null)
return;
//
if (dao != null) {
try {
// query startup components and add them to a list of candidates
String[] startup = dao.get_string_seq("Startup");
for (int i = 0; i < startup.length; i++) {
// TODO simulator test workaround
if (startup[i].length() == 0)
continue;
activationRequestsList.add(startup[i]);
}
} catch (Throwable th) {
logger.log(Level.WARNING, "Failed to retrieve list of startup components.", th);
}
}
//
// autostart components (<component>.Autostart attribute)
//
final String TRUE_STRING = "true";
{
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 name of component '" + ids[i] + "' defined.");
continue;
}
// read autostart silently
String autostart = readStringCharacteristics(componentsDAO, ids[i] + "/Autostart", true);
if (autostart == null) {
logger.log(Level.WARNING, "Misconfigured CDB, there is no autostart attribute of component '" + ids[i] + "' defined.");
continue;
} else if (autostart.equalsIgnoreCase(TRUE_STRING)) {
activationRequestsList.add(name);
}
}
} catch (Throwable ex) {
logger.log(Level.WARNING, "Failed to retrieve list of components.", ex);
}
}
// now gather list of all containers to be started up (they will autostart components by default)
// by filtering out all components that are not hosted by auto-start containers
// leave only components that have "*" listed as container
LinkedHashSet startupContainers = new LinkedHashSet();
Iterator<String> iterator = activationRequestsList.iterator();
while (iterator.hasNext()) {
String name = iterator.next();
try {
// get container
String containerName = readStringCharacteristics(componentsDAO, name + "/Container", true);
if (containerName == null) {
iterator.remove();
continue;
} else if (containerName.equals(ComponentSpec.COMPSPEC_ANY)) {
// leave it in the list
continue;
}
// get its deploy info
String host = readStringCharacteristics(containersDAO, containerName + "/DeployInfo/Host", true);
String startOnDemand = readStringCharacteristics(containersDAO, containerName + "/DeployInfo/StartOnDemand", true);
if (host != null && startOnDemand != null && startOnDemand.equalsIgnoreCase("TRUE"))
startupContainers.add(containerName);
// remove (or is it auto-started by starting a container or is it not hosted by auto-start container)
iterator.remove();
} catch (Throwable ex) {
logger.log(Level.WARNING, "Failed to retrieve list of components.", ex);
}
}
int activated = 0;
// autostart containers
iterator = startupContainers.iterator();
while (iterator.hasNext()) {
String containerName = (String) iterator.next();
try {
startUpContainer(containerName);
} catch (Throwable ex) {
logger.log(Level.WARNING, "Failed to auto-start container to auto-start components.", ex);
}
}
// activate startup components (no container specified)
StatusHolder status = new StatusHolder();
iterator = activationRequestsList.iterator();
while (iterator.hasNext()) {
String name = iterator.next();
try {
URI uri = CURLHelper.createURI(name);
internalRequestComponent(this.getHandle(), uri, status);
if (status.getStatus() != ComponentStatus.COMPONENT_ACTIVATED)
logger.log(Level.FINE, "Failed to auto-activate requested component '" + name + "', reason: '" + status.getStatus() + "'.");
else
activated++;
} catch (Throwable ex) {
CoreException ce = new CoreException("Failed to request component '" + name + "'.", ex);
reportException(ce);
}
}
}
use of com.cosylab.acs.maci.CoreException in project ACS by ACS-Community.
the class ManagerImpl method refreshComponentsList.
/**
* Searches dao for all potential (nodes containing Name attribute) ComponentInfo nodes.
* @param dc dao to be searched.
* @returns list of all potential ComponentInfo nodes.
*/
private String[] refreshComponentsList(DAOProxy dc) {
ArrayList componentList = new ArrayList();
try {
LinkedHashSet nodes = new LinkedHashSet();
// current
nodes.add("");
String[] subnodes = cdbAccess.getSubNodes(dc);
if (subnodes != null)
for (int i = 0; i < subnodes.length; i++) nodes.add(subnodes[i]);
Iterator iter = nodes.iterator();
while (iter.hasNext()) {
String prefix = iter.next().toString();
if (prefix.length() > 0)
prefix += "/";
String attributes = dc.get_field_data(prefix + "_characteristics");
// convert into array
StringTokenizer tokenizer = new StringTokenizer(attributes, ",");
while (tokenizer.hasMoreTokens()) {
String subname = tokenizer.nextToken().toString();
String componentName = prefix + subname;
/// @todo this could be done better (to check if all attributes exist)
if (readStringCharacteristics(dc, componentName + "/Name", true) != null)
componentList.add(componentName);
}
}
} catch (Throwable th) {
CoreException ce = new CoreException("Failed to obtain list of all components.", th);
logger.log(Level.WARNING, ce.getMessage(), ce);
}
String[] retVal = new String[componentList.size()];
componentList.toArray(retVal);
logger.log(Level.INFO, "Found " + retVal.length + " component entries in the configuration database.");
return retVal;
}
use of com.cosylab.acs.maci.CoreException in project ACS by ACS-Community.
the class ManagerImpl method isServiceComponent.
/**
* Checks if component name is a service component name, list of names is defined in the CDB.
*
* @param name name to be checked, non-<code>null</code>
* @returns <code>true</code> if component name is service component name, <code>false</code> otherwise
*/
public boolean isServiceComponent(String name) {
assert (name != null);
boolean retVal = false;
// get CDB access dao
DAOProxy dao = getManagerDAOProxy();
if (dao != null) {
try {
// query
String[] names = dao.get_string_seq("ServiceComponents");
// find it
for (int i = 0; i < names.length; i++) if (name.equals(names[i])) {
retVal = true;
break;
}
} catch (Throwable ex) {
CoreException ce = new CoreException("Failed to retrieve list of service components.", ex);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
return retVal;
}
Aggregations