Search in sources :

Example 1 with ManagerImpl

use of com.cosylab.acs.maci.manager.ManagerImpl in project ACS by ACS-Community.

the class ManagerImplSerializationTest method testContainerDie.

public void testContainerDie() throws Throwable {
    // should be something else then deafault because
    // the default is in use by the Manager
    Properties table = new Properties();
    table.put("OAPort", "12121");
    // new ORB instance
    ORB ourOrb = ORB.init(new String[0], table);
    try {
        POA rootPOA = POAHelper.narrow(ourOrb.resolve_initial_references("RootPOA"));
        // activate POA
        POAManager manager = rootPOA.the_POAManager();
        manager.activate();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ContainerProxyImpl activator = new ContainerProxyImpl(clientName);
    si.ijs.maci.ClientInfo clientInfo = manager.login(activator._this(ourOrb));
    if (clientInfo == null || clientInfo.h == 0)
        fail("Unable to login to manager");
    // just destroy its ORB
    ourOrb.shutdown(true);
    // get object as it is stored in recovery store
    ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
    HandleDataStore activators = newManager.getContainers();
    // the client now is still in stored data
    assertEquals(activators.first(), 1);
    newManager.initialize(null, null, null, null, null);
    // now wait for timer task to remove client
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail();
    }
    // since the client died the menager automaticaly log it out    
    activators = newManager.getClients();
    // not any more
    assertEquals(activators.first(), 0);
}
Also used : POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) HandleDataStore(com.cosylab.acs.maci.manager.HandleDataStore) Properties(java.util.Properties) ORB(org.omg.CORBA.ORB)

Example 2 with ManagerImpl

use of com.cosylab.acs.maci.manager.ManagerImpl in project ACS by ACS-Community.

the class ManagerImplSerializationTest method testClientLogin.

public void testClientLogin() {
    // login a client
    ClientProxyImpl client = new ClientProxyImpl(clientName, myManager.getManagerEngine().getLogger());
    client.login(orb, manager);
    // get object as it is stored in recovery store
    ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
    // since we used clean recovery store we must have our client only there    
    HandleDataStore clients = newManager.getClients();
    assertEquals(clients.first(), 1);
    com.cosylab.acs.maci.ClientInfo clientInfo = (com.cosylab.acs.maci.ClientInfo) clients.get(clients.first());
    assertEquals(clientInfo.getName(), clientName);
    client.logout();
    // read state again
    newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
    clients = newManager.getClients();
    assertEquals(clients.first(), 0);
}
Also used : ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) ClientProxyImpl(com.cosylab.acs.maci.plug.ClientProxyImpl) HandleDataStore(com.cosylab.acs.maci.manager.HandleDataStore)

Example 3 with ManagerImpl

use of com.cosylab.acs.maci.manager.ManagerImpl in project ACS by ACS-Community.

the class ManagerImplSerializationTest method testClientDie.

public void testClientDie() {
    // should be something else then deafault because
    // the default is in use by the Manager
    Properties table = new Properties();
    table.put("OAPort", "12121");
    // new ORB instance
    ORB ourOrb = ORB.init(new String[0], table);
    try {
        POA rootPOA = POAHelper.narrow(ourOrb.resolve_initial_references("RootPOA"));
        // activate POA
        POAManager manager = rootPOA.the_POAManager();
        manager.activate();
    } catch (Exception e) {
        e.printStackTrace();
    }
    ClientProxyImpl client = new ClientProxyImpl(clientName, myManager.getManagerEngine().getLogger());
    client.login(ourOrb, manager);
    // just destroy its ORB
    ourOrb.shutdown(true);
    // get object as it is stored in recovery store
    ManagerImpl newManager = (ManagerImpl) deserializeManager(new ManagerImpl());
    HandleDataStore clients = newManager.getClients();
    // the client now is still in stored data
    assertEquals(clients.first(), 1);
    newManager.initialize(null, null, null, null, null);
    // now wait for timer task to remove client
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
        fail();
    }
    // since the client died the menager automaticaly log it out    
    clients = newManager.getClients();
    // not any more
    assertEquals(clients.first(), 0);
}
Also used : POA(org.omg.PortableServer.POA) POAManager(org.omg.PortableServer.POAManager) ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) ClientProxyImpl(com.cosylab.acs.maci.plug.ClientProxyImpl) HandleDataStore(com.cosylab.acs.maci.manager.HandleDataStore) Properties(java.util.Properties) ORB(org.omg.CORBA.ORB)

Example 4 with ManagerImpl

use of com.cosylab.acs.maci.manager.ManagerImpl in project ACS by ACS-Community.

the class DeserializeManagerFromFile method main.

/**
	 * @param args
	 */
public static void main(String[] args) throws Throwable {
    File f = new File(args[0]);
    ObjectInputStream obj = new ObjectInputStream(new FileInputStream(f));
    // we cast directly to the implementation
    ManagerImpl manager = (ManagerImpl) obj.readObject();
    {
        //
        // list all active components
        //
        HandleDataStore components = manager.getComponents();
        System.out.println("Capacity of handle data store: " + components.capacity());
        System.out.println(components.size() + " component(s) stored:");
        int h = components.first();
        while (h != 0) {
            ComponentInfo componentInfo = (ComponentInfo) components.get(h);
            System.out.println("\tName            : " + componentInfo.name);
            System.out.println("\tHandle          : " + componentInfo.h + ", " + HandleHelper.toString(componentInfo.h));
            System.out.println("\tType            : " + componentInfo.type);
            System.out.println("\tCode            : " + componentInfo.code);
            System.out.println("\tContainer name  : " + componentInfo.container_name);
            System.out.println("\tContainer handle: " + HandleHelper.toString(componentInfo.container));
            System.out.println("\tClients         : count = " + componentInfo.clients.length);
            for (int j = 0; j < componentInfo.clients.length; j++) System.out.println("\t             \t" + componentInfo.clients[j]);
            System.out.println("\t-------------------------------");
            h = components.next(h);
        }
    }
    System.out.println();
    System.out.println();
    System.out.println();
    {
        //
        // list all active containers
        //
        HandleDataStore containers = manager.getContainers();
        System.out.println("Capacity of handle data store: " + containers.capacity());
        System.out.println(containers.size() + " container(s) returned:");
        int h = containers.first();
        while (h != 0) {
            ContainerInfo containersInfo = (ContainerInfo) containers.get(h);
            System.out.println("\tName            : " + containersInfo.name);
            System.out.println("\tHandle          : " + containersInfo.h + ", " + HandleHelper.toString(containersInfo.h));
            System.out.println("\tComponents      : count = " + containersInfo.components.length);
            for (int j = 0; j < containersInfo.components.length; j++) System.out.println("\t             \t" + containersInfo.components[j]);
            System.out.println("\t-------------------------------");
        }
    }
    System.out.println();
    System.out.println();
    System.out.println();
    {
        //
        // list all active clients
        //
        HandleDataStore clients = manager.getClients();
        System.out.println("Capacity of handle data store: " + clients.capacity());
        System.out.println(clients.size() + " clients(s) returned:");
        int h = clients.first();
        while (h != 0) {
            ClientInfo clientsInfo = (ClientInfo) clients.get(h);
            System.out.println("\tName            : " + clientsInfo.name);
            System.out.println("\tHandle          : " + clientsInfo.h + ", " + HandleHelper.toString(clientsInfo.h));
            System.out.println("\tComponents      : count = " + clientsInfo.components.length);
            for (int j = 0; j < clientsInfo.components.length; j++) System.out.println("\t             \t" + clientsInfo.components[j]);
            System.out.println("\t-------------------------------");
        }
    }
    System.out.println();
    System.out.println();
    System.out.println();
    {
        //
        // list all active administrators
        //
        HandleDataStore clients = manager.getAdministrators();
        System.out.println("Capacity of handle data store: " + clients.capacity());
        System.out.println(clients.size() + " administrators(s) returned:");
        int h = clients.first();
        while (h != 0) {
            ClientInfo clientsInfo = (ClientInfo) clients.get(h);
            System.out.println("\tName            : " + clientsInfo.name);
            System.out.println("\tHandle          : " + clientsInfo.h + ", " + HandleHelper.toString(clientsInfo.h));
            System.out.println("\tComponents      : count = " + clientsInfo.components.length);
            for (int j = 0; j < clientsInfo.components.length; j++) System.out.println("\t             \t" + clientsInfo.components[j]);
            System.out.println("\t-------------------------------");
        }
    }
    System.out.println();
    System.out.println();
    System.out.println();
    System.out.println("# of unavailable components in a map: " + manager.getUnavailableComponents().size());
    System.out.println("# of default components in a map: " + manager.getDefaultComponents().size());
    System.out.println("# of active alarms in a map: " + manager.getActiveAlarms().size());
    System.out.println("# of released handles in a map: " + manager.getReleasedHandles().size());
}
Also used : ManagerImpl(com.cosylab.acs.maci.manager.ManagerImpl) ContainerInfo(si.ijs.maci.ContainerInfo) HandleDataStore(com.cosylab.acs.maci.manager.HandleDataStore) ComponentInfo(si.ijs.maci.ComponentInfo) ClientInfo(si.ijs.maci.ClientInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with ManagerImpl

use of com.cosylab.acs.maci.manager.ManagerImpl 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

ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)16 ComponentInfo (com.cosylab.acs.maci.ComponentInfo)4 HandleDataStore (com.cosylab.acs.maci.manager.HandleDataStore)4 ContainerInfo (com.cosylab.acs.maci.ContainerInfo)3 DefaultCORBAService (com.cosylab.acs.maci.plug.DefaultCORBAService)3 CDBAccess (com.cosylab.cdb.client.CDBAccess)3 File (java.io.File)3 ORB (org.omg.CORBA.ORB)3 POA (org.omg.PortableServer.POA)3 ClientInfo (com.cosylab.acs.maci.ClientInfo)2 ClientProxyImpl (com.cosylab.acs.maci.plug.ClientProxyImpl)2 Properties (java.util.Properties)2 POAManager (org.omg.PortableServer.POAManager)2 SnapshotPrevayler (org.prevayler.implementation.SnapshotPrevayler)2 LogConfig (alma.acs.logging.config.LogConfig)1 LogConfigException (alma.acs.logging.config.LogConfigException)1 CoreException (com.cosylab.acs.maci.CoreException)1 CORBATransport (com.cosylab.acs.maci.plug.CORBATransport)1 ManagerProxyImpl (com.cosylab.acs.maci.plug.ManagerProxyImpl)1 NamingServiceRemoteDirectory (com.cosylab.acs.maci.plug.NamingServiceRemoteDirectory)1