Search in sources :

Example 1 with LogConfigException

use of alma.acs.logging.config.LogConfigException in project ACS by ACS-Community.

the class AcsContainer method initialize.

/**
	 * Container initialization such as logging in to the manager, configuring logging, initializing the alarm system.
	 * This is taken out of the ctor just to keep is lean and be able to instantiate a minimum container for testing.
	 * @throws AcsJContainerServicesEx for any serious issue that should make container start fail.
	 */
void initialize() throws AcsJContainerEx {
    // CDB ref 
    try {
        org.omg.CORBA.Object dalObj = m_managerProxy.get_service("CDB", false);
        sharedCdbRef = DALHelper.narrow(dalObj);
    } catch (Exception ex) {
        m_logger.log(Level.SEVERE, "Failed to access the CDB.", ex);
        throw new AcsJContainerEx(ex);
    }
    if (sharedCdbRef == null) {
        m_logger.log(Level.SEVERE, "Failed to access the CDB.");
        throw new AcsJContainerEx();
    }
    // CDB container config (must be done before manager login)
    initFromCdb(true);
    // TODO: sharedCdbRef.add_change_listener / listen_for_changes and call initFromCdb(false) on change.
    // manager login
    System.out.println(ContainerOperations.ContainerStatusMgrInitBeginMsg);
    // TODO: Use CDB attributes ManagerRetry and Recovery for manager login.
    loginToManager(m_managerRetry);
    System.out.println(ContainerOperations.ContainerStatusMgrInitEndMsg);
    // init logging 
    logConfig = ClientLogManager.getAcsLogManager().getLogConfig();
    // logConfig.setInternalLogger(m_logger);
    logConfig.setCDBLoggingConfigPath("MACI/Containers/" + m_containerName);
    logConfig.setCDB(sharedCdbRef);
    try {
        logConfig.initialize(false);
    } catch (LogConfigException ex) {
        // if the CDB can't be read, we still want to run the container, thus we only log the problem here
        m_logger.log(Level.FINE, "Failed to configure logging (default values will be used).", ex);
    }
    // init the alarm system
    //
    // TODO: clean up the construction of CS which is ad-hoc implemented right before ACS 7.0
    // in order to allow CERN alarm libs to get their static field for ContainerServices set.
    // Currently the alarm system acts under the container name.
    // Setting of static fields in the AS classes should be removed altogether.
    // TODO: maybe we should pass a alarms@container logger instead of the normal one
    m_alarmContainerServices = new ContainerServicesImpl(m_managerProxy, sharedCdbRef, m_acsCorba.createPOAForComponent("alarmSystem"), m_acsCorba, m_logger, 0, m_containerName, null, containerThreadFactory) {

        private AcsLogger alarmLogger;

        public AcsLogger getLogger() {
            if (alarmLogger == null) {
                // @TODO perhaps get a container logger "alarms@containername"
                alarmLogger = ClientLogManager.getAcsLogManager().getLoggerForContainer(getName());
            }
            return alarmLogger;
        }
    };
    try {
        ACSAlarmSystemInterfaceFactory.init(m_alarmContainerServices);
    } catch (Throwable thr) {
        AcsJContainerEx ex = new AcsJContainerEx(thr);
        ex.setContextInfo("Error initializing the alarm system factory");
        throw ex;
    }
    // enable (throttle) alarms from the logging subsystem
    ClientLogManager.LogAlarmHandler logAlarmHandler = new ClientLogManager.LogAlarmHandler() {

        @Override
        public void raiseAlarm(String faultFamily, String faultMember, int faultCode) throws AcsJCouldntPerformActionEx {
            m_alarmContainerServices.getAlarmSource().raiseAlarm(faultFamily, faultMember, faultCode);
        }

        @Override
        public void clearAlarm(String faultFamily, String faultMember, int faultCode) throws AcsJCouldntPerformActionEx {
            m_alarmContainerServices.getAlarmSource().clearAlarm(faultFamily, faultMember, faultCode);
        }
    };
    ClientLogManager.getAcsLogManager().enableLoggingAlarms(logAlarmHandler);
    // init the BACI framework
    try {
        Class<?> clazz = Class.forName("alma.ACS.jbaci.BACIFramework");
        Object baciFramework = clazz.getField("INSTANCE").get(null);
        clazz.getMethod("initialize", ThreadFactory.class).invoke(baciFramework, containerThreadFactory);
    } catch (Exception e) {
        AcsJContainerEx ex = new AcsJContainerEx(e);
        ex.setContextInfo("Error initializing the BACI framework");
        // TODO: This is temporary, just to avoid test crashes. The exception should be actually thrown
        m_logger.log(AcsLogLevel.WARNING, "Error initializing the BACI framework, container will run withouth the BACI Framework initialized", ex);
    //throw ex;
    }
    // unleash any waiting ORB threads that were held until container init has finished
    containerStartOrbThreadGate.countDown();
}
Also used : AcsJContainerEx(alma.JavaContainerError.wrappers.AcsJContainerEx) ThreadFactory(java.util.concurrent.ThreadFactory) ClientLogManager(alma.acs.logging.ClientLogManager) LogConfigException(alma.acs.logging.config.LogConfigException) AcsJException(alma.acs.exceptions.AcsJException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) LogConfigException(alma.acs.logging.config.LogConfigException) AcsLogger(alma.acs.logging.AcsLogger)

Example 2 with LogConfigException

use of alma.acs.logging.config.LogConfigException 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();
}
Also used : SnapshotPrevayler(org.prevayler.implementation.SnapshotPrevayler) LogConfigException(alma.acs.logging.config.LogConfigException) ManagerProxyImpl(com.cosylab.acs.maci.plug.ManagerProxyImpl) DefaultCORBAService(com.cosylab.acs.maci.plug.DefaultCORBAService) AcsORBProfiler(org.jacorb.orb.acs.AcsORBProfiler) NamingServiceRemoteDirectory(com.cosylab.acs.maci.plug.NamingServiceRemoteDirectory) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB) Context(javax.naming.Context) POA(org.omg.PortableServer.POA) CDBAccess(com.cosylab.cdb.client.CDBAccess) Hashtable(java.util.Hashtable) LogConfigException(alma.acs.logging.config.LogConfigException) CoreException(com.cosylab.acs.maci.CoreException) CoreException(com.cosylab.acs.maci.CoreException) ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) CORBATransport(com.cosylab.acs.maci.plug.CORBATransport) File(java.io.File) ORB(org.omg.CORBA.ORB) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB) LogConfig(alma.acs.logging.config.LogConfig)

Aggregations

LogConfigException (alma.acs.logging.config.LogConfigException)2 AcsJContainerEx (alma.JavaContainerError.wrappers.AcsJContainerEx)1 AcsJException (alma.acs.exceptions.AcsJException)1 AcsLogger (alma.acs.logging.AcsLogger)1 ClientLogManager (alma.acs.logging.ClientLogManager)1 LogConfig (alma.acs.logging.config.LogConfig)1 CoreException (com.cosylab.acs.maci.CoreException)1 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)1 CORBATransport (com.cosylab.acs.maci.plug.CORBATransport)1 DefaultCORBAService (com.cosylab.acs.maci.plug.DefaultCORBAService)1 ManagerProxyImpl (com.cosylab.acs.maci.plug.ManagerProxyImpl)1 NamingServiceRemoteDirectory (com.cosylab.acs.maci.plug.NamingServiceRemoteDirectory)1 CDBAccess (com.cosylab.cdb.client.CDBAccess)1 File (java.io.File)1 Hashtable (java.util.Hashtable)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 Context (javax.naming.Context)1 AcsORBProfiler (org.jacorb.orb.acs.AcsORBProfiler)1 AcsProfilingORB (org.jacorb.orb.acs.AcsProfilingORB)1