use of com.cosylab.acs.maci.CoreException in project ACS by ACS-Community.
the class ManagerImpl method initializeFederation.
/*****************************************************************************/
/************************* [ Federation methods ] ****************************/
/*****************************************************************************/
/**
* Initialize manager federation.
*/
public void initializeFederation(Hashtable federationDirectoryProperties) throws CoreException {
assert (federationDirectoryProperties != null);
//
// read domain list
//
HashSet givenDomainList = new HashSet();
try {
String domainList = System.getProperty(NAME_DOMAIN_LIST);
if (domainList != null) {
// parse space/comma separated list
StringTokenizer tokenizer = new StringTokenizer(domainList, ", ");
while (tokenizer.hasMoreTokens()) {
String domainName = tokenizer.nextToken();
// do not allow '/' in domain names
if (domainName.indexOf('/') == -1)
givenDomainList.add(domainName);
}
}
if (givenDomainList.size() > 0)
logger.log(Level.INFO, "Using domain list: " + givenDomainList + ".");
} catch (Throwable t) {
logger.log(Level.WARNING, "Failed to parse domain list '" + NAME_DOMAIN_LIST + "' variable, " + t.getMessage(), t);
}
// recovery data consistency check
if (domains.size() != 0 && !domains.equals(givenDomainList)) {
CoreException ie = new CoreException("Given domain list is not consistent with recovery data: " + givenDomainList + " != " + domains + ".");
throw ie;
} else if (domains.size() == 0 && givenDomainList.size() != 0)
domains = givenDomainList;
// no domain to control, no federation
if (domains.size() == 0) {
logger.log(Level.CONFIG, "No domain list given, manager federation disabled.");
return;
}
if (remoteDirectoryComponentReference == null) {
logger.log(Level.WARNING, "No valid local domain naming service reference found, manager federation disabled.");
return;
}
//
// read federation naming service
//
String domainNS = System.getProperty(NAME_DOMAIN_DIRECTORY);
if (domainNS == null) {
logger.log(Level.WARNING, "No federation directory reference given, manager federation disabled.");
return;
}
// set NS address
federationDirectoryProperties.put(Context.PROVIDER_URL, domainNS);
logger.log(Level.INFO, "Connecting to the federation directory with reference '" + domainNS + "'...");
try {
federationDirectory = new InitialContext(federationDirectoryProperties);
} catch (Throwable th) {
logger.log(Level.INFO, "Failed to connect to the federation directory with reference '" + domainNS + "'...", th);
return;
}
logger.log(Level.INFO, "Connected to the federation directory with reference '" + domainNS + "'.");
// register domains
Iterator iter = domains.iterator();
while (iter.hasNext()) {
bind(federationDirectory, dottedToHierarchical(iter.next().toString()), null, remoteDirectoryComponentReference);
}
federationEnabled = true;
logger.log(Level.INFO, "Manager federation enabled.");
// set domain name string (one name or set of names)
if (domains.size() == 1)
domain = domains.iterator().next().toString();
else
domain = domains.toString();
}
use of com.cosylab.acs.maci.CoreException 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.CoreException 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.CoreException in project ACS by ACS-Community.
the class ManagerImpl method lookup.
/**
* Lookups for an object in remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
*
* @param remoteDirectory remote directory context to be used.
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
* @return object object found in the remote directory, <code>null<code> if nout found
*/
private Object lookup(Context remoteDirectory, String name, String type) {
assert (name != null);
// do not look for interdomain names
if (name.startsWith(CURL_URI_SCHEMA))
return null;
Object resolved = null;
if (remoteDirectory != null) {
try {
NameParser parser = remoteDirectory.getNameParser("");
Name n;
if (type != null)
n = parser.parse(name + "." + type);
else
n = parser.parse(name);
resolved = remoteDirectory.lookup(n);
} catch (NamingException ne) {
CoreException ce = new CoreException("Failed to lookup name '" + name + "' in the remote directory.", ne);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
return resolved;
}
use of com.cosylab.acs.maci.CoreException in project ACS by ACS-Community.
the class ManagerEngine method initializeManager.
/**
* Initialize and activate Manager.
*/
private void initializeManager() throws Throwable {
logger = ClientLogManager.getAcsLogManager().getLoggerForApplication("Manager", true);
logger.info("Initializing Manager.");
//
// CORBA
//
// obtain CORBA Service
corbaService = new DefaultCORBAService(logger);
// get ORB
final ORB orb = corbaService.getORB();
if (orb == null) {
CoreException ce = new CoreException("CORBA Service can not provide ORB.");
throw ce;
}
// get RootPOA
POA rootPOA = corbaService.getRootPOA();
if (rootPOA == null) {
CoreException ce = new CoreException("CORBA Service can not provide RootPOA.");
throw ce;
}
//
// Remote Directory
//
NamingServiceRemoteDirectory remoteDirectory = new NamingServiceRemoteDirectory(orb, logger);
Context context = null;
if (remoteDirectory != null)
context = remoteDirectory.getContext();
//
// Initialize CORBA
//
// set USER_ID, PERSISTENT policies
org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
/*
// set USER_ID, PERSISTENT,BIDIRECTIONAL policies
org.omg.CORBA.Policy [] policies = new org.omg.CORBA.Policy[3];
*/
policies[0] = rootPOA.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
policies[1] = rootPOA.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
/*
// create BIDIRECTIONAL policy
Any bidirValue = orb.create_any();
BidirectionalPolicyValueHelper.insert(bidirValue, BOTH.value);
policies[2] = orb.create_policy(BIDIRECTIONAL_POLICY_TYPE.value, bidirValue);
*/
// create ManagerPOA
managerPOA = rootPOA.create_POA("ManagerPOA", rootPOA.the_POAManager(), policies);
// destroy policies
for (int i = 0; i < policies.length; i++) policies[i].destroy();
// initialize Manager implementation
// allow object reference serialization
CORBAReferenceSerializator.setOrb(orb);
manager = new ManagerImpl();
manager.setDomain(MANAGER_DOMAIN);
recoveryLocation = FileHelper.getTempFileName(null, RECOVERY_DIR_NAME);
String readRecovery = System.getProperties().getProperty("Manager.recovery", "true");
if (readRecovery.equalsIgnoreCase("false")) {
// if we are not interested in recovery files just delete them
File recoveryDir = new File(recoveryLocation);
//recoveryDir.delete();
File[] files = recoveryDir.listFiles();
for (int i = 0; files != null && i < files.length; i++) files[i].delete();
// Now check if there are log files left. Maybe user do not have enough permision
// or we are didn't set proper permission before Manager killed.
// That can lead to unwanted or illegal state so we will refuse to continue
files = recoveryDir.listFiles();
for (int i = 0; files != null && i < files.length; i++) {
if (files[i].getName().endsWith(".commandLog"))
throw new Exception("Some recovery files are left in recovery location probably because of permission\nUnable to start without recovery state!");
}
} else {
// remove old recovery files
RecoveryFilesRemover.removeRecoveryFiles(new File(recoveryLocation));
}
SnapshotPrevayler prevayler = null;
if (isPrevaylerDisabled) {
System.out.println("Prevayler disabled!");
} else {
prevayler = new SnapshotPrevayler(manager, recoveryLocation);
if (readRecovery.equalsIgnoreCase("false")) {
// just to invalidate prevaylers message
System.out.println("Skipping saved manager state!");
}
manager = (ManagerImpl) prevayler.system();
}
CDBAccess cdbAccess = new CDBAccess(orb, logger);
LogConfig logConfig = ClientLogManager.getAcsLogManager().getLogConfig();
logConfig.setCDBLoggingConfigPath("MACI/Managers/Manager");
logConfig.setCDB(cdbAccess.connectAndGetDAL());
try {
logConfig.initialize(false);
} catch (LogConfigException ex) {
// if the CDB can't be read, we still want to run the manager, so
// we only log the problems
logger.log(Level.FINE, "Failed to configure logging (default values will be used). Reason: " + ex.getMessage());
}
// initialize manager "mock" container services
ManagerContainerServices managerContainerServices = new ManagerContainerServices(orb, managerPOA, cdbAccess.getDAL(), logger);
manager.initialize(prevayler, cdbAccess, context, logger, managerContainerServices);
manager.setShutdownImplementation(shutdownImplementation);
// setup ORB profiling
try {
if (orb instanceof AcsProfilingORB) {
AcsORBProfiler profiler = new ManagerOrbProfiler(manager, logger);
((AcsProfilingORB) orb).registerAcsORBProfiler(profiler);
logger.finer("Orb profiling set up, using class " + ManagerOrbProfiler.class.getName());
}
} catch (Throwable th) {
logger.log(Level.WARNING, "Failed to setup ORB profiling.", th);
}
if (prevayler != null) {
FileHelper.setFileAttributes("g+w", recoveryLocation);
// create new task for snapshoot creation,
final long MINUTE_IN_MS = 60 * 1000;
new RecoverySnapshotTask(prevayler, 1 * MINUTE_IN_MS, recoveryLocation, manager.getStatePersitenceFlag());
}
// initialize Manager CORBA Proxy (create servant)
managerProxy = new ManagerProxyImpl(manager, logger);
//activate object
managerPOA.activate_object_with_id(MANAGER_ID, managerProxy);
// get object reference from the servant
org.omg.CORBA.Object obj = managerPOA.servant_to_reference(managerProxy);
managerReference = ManagerHelper.narrow(obj);
// get IOR
String ior = orb.object_to_string(managerReference);
// notify user
logger.info("Manager activated with " + ior);
// register special service components to the Manager
manager.setManagerComponentReference(managerReference);
// set transport
manager.setTransport(new CORBATransport(orb, ior));
// register NameService
if (remoteDirectory != null) {
String reference = remoteDirectory.getReference();
if (reference != null) {
// convert iiop to corbaloc
if (reference.startsWith("iiop://")) {
reference = reference.replaceFirst("iiop://", "corbaloc::");
if (reference.charAt(reference.length() - 1) != '/')
reference += "/NameService";
else
reference += "NameService";
}
}
try {
obj = NamingContextHelper.narrow(orb.string_to_object(reference));
} catch (Exception ex) {
// Something went wrong getting the NS
logger.log(Level.SEVERE, "Error getting the NameServer. Manager exiting...");
this.shutdownImplementation.shutdown(false);
}
manager.setRemoteDirectoryComponentReference(obj);
}
// intitialize federation here - after remote directory is set (if it is)
// (this is not a nice solution)
Hashtable federationDirectoryProperties = new Hashtable();
// set CosNamingFactory
federationDirectoryProperties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
// set orb
federationDirectoryProperties.put("java.naming.corba.orb", orb);
manager.initializeFederation(federationDirectoryProperties);
// initialize remote logging
new Thread(new Runnable() {
public void run() {
ClientLogManager.getAcsLogManager().initRemoteLogging(orb, managerReference, manager.getHandle(), true);
}
}, "Remote logging initializer").start();
manager.initializationDone();
}
Aggregations