Search in sources :

Example 1 with ORB

use of org.omg.CORBA.ORB in project ACS by ACS-Community.

the class MaciSupervisorTest method setUp.

@Override
public void setUp() throws Exception {
    System.out.println("\n--- " + getName() + " ----------------");
    // make the manager
    // -----------------------------------------------------------------
    orb = Mockito.mock(ORB.class);
    manager = Mockito.mock(Manager.class);
    administrator = Mockito.mock(Administrator.class);
    final int hhhhh = 0;
    final int[] empty = new int[] {};
    ComponentInfo comp100 = new ComponentInfo("type", "code", null, "comp100", empty, 10, "cont10", 100, 0, new String[] {});
    ComponentInfo comp200 = new ComponentInfo("type", "code", null, "comp200", empty, 20, "cont20", 200, 0, new String[] {});
    ComponentInfo comp300 = new ComponentInfo("type", "code", null, "comp300", empty, 30, "cont30", 300, 0, new String[] {});
    ComponentInfo[] one_comp = { comp100 };
    ComponentInfo[] two_comps = { comp100, comp200 };
    ComponentInfo[] three_comps = { comp100, comp200, comp300 };
    ContainerInfo cont10 = new ContainerInfo("cont10", 10, null, empty);
    ContainerInfo cont20 = new ContainerInfo("cont20", 20, null, empty);
    ContainerInfo cont30 = new ContainerInfo("cont30", 30, null, empty);
    ContainerInfo[] one_cont = { cont10 };
    ContainerInfo[] two_conts = { cont10, cont20 };
    ContainerInfo[] three_conts = { cont10, cont20, cont30 };
    ClientInfo clientA = new ClientInfo(0, null, empty, "clientA", 0);
    ClientInfo client1 = new ClientInfo(1, null, empty, "client1", 0);
    ClientInfo client2 = new ClientInfo(2, null, empty, "client2", 0);
    ClientInfo client3 = new ClientInfo(3, null, empty, "client3", 0);
    ClientInfo[] one_client = { client1 };
    ClientInfo[] two_clients = { client1, client2 };
    ClientInfo[] three_clients = { client1, client2, client3 };
    Mockito.when(orb.string_to_object("dummy")).thenReturn(manager);
    Mockito.when(manager.login(administrator)).thenReturn(clientA);
    Mockito.when(manager.get_component_info(hhhhh, empty, "*", "*", false)).thenReturn(one_comp, two_comps, three_comps);
    Mockito.when(manager.get_container_info(hhhhh, empty, "*")).thenReturn(one_cont, one_cont, two_conts, three_conts);
    Mockito.when(manager.get_client_info(hhhhh, empty, "*")).thenReturn(one_client, two_clients, three_clients, two_clients, three_clients);
    // make the supervisor
    // -----------------------------------------------------------------
    log = new Logger("Test", null) {

        final long start = System.nanoTime();

        @Override
        public void log(LogRecord r) {
            long sinceStart = (System.nanoTime() - start) / 1000 / 1000 / 1000;
            System.out.println(String.format("%2d", sinceStart) + "  " + r.getLevel() + "  " + r.getMessage());
        }
    };
    log.setLevel(Level.FINE);
    testee = new MaciSupervisor("Test", "dummy", orb, log);
    testee.acImpl = testee.new AdministratorImplementation() {

        @Override
        protected Administrator asCorbaObject(ORB orb) {
            return administrator;
        }
    };
    testee.start();
    // assertions
    // ----------------------------------------------------------------
    maciListener = new MaciInfoListener();
    MaciInfo maciInformation = testee.getMaciInformation();
    maciInformation.addTreeModelListener(maciListener);
}
Also used : Manager(si.ijs.maci.Manager) Logger(java.util.logging.Logger) Administrator(si.ijs.maci.Administrator) LogRecord(java.util.logging.LogRecord) ContainerInfo(si.ijs.maci.ContainerInfo) ComponentInfo(si.ijs.maci.ComponentInfo) ClientInfo(si.ijs.maci.ClientInfo) ORB(org.omg.CORBA.ORB)

Example 2 with ORB

use of org.omg.CORBA.ORB in project ACS by ACS-Community.

the class AdvancedContainerServicesImpl method corbaObjectToString.

/* (non-Javadoc)
	 * @see alma.acs.container.ContainerServices#corbaObjectToString(org.omg.CORBA.Object)
	 */
public String corbaObjectToString(org.omg.CORBA.Object objRef) {
    ORB orb = getORB();
    String str = orb.object_to_string(objRef);
    logger.finer("converted corba object reference of type " + objRef.getClass().getName() + " to the string " + str);
    return str;
}
Also used : ORB(org.omg.CORBA.ORB)

Example 3 with ORB

use of org.omg.CORBA.ORB in project ACS by ACS-Community.

the class ComponentClientTestCase method connectToManager.

/**
	 * Connects to the ACS Manager using {@link AcsManagerProxy}.
	 * @throws Exception
	 */
protected void connectToManager() throws Exception {
    if (System.getProperty("ACS.manager") != null) {
        m_managerLoc = System.getProperty("ACS.manager").trim();
    } else {
        // default = localhost
        String host = ACSPorts.getIP();
        m_managerLoc = "corbaloc::" + host + ":" + ACSPorts.getManagerPort() + "/Manager";
    }
    managerClientImpl = new ManagerClient(getFullName(), m_logger) {

        public void disconnect() {
            m_logger.info("disconnected from manager");
            m_acsManagerProxy.logoutFromManager();
            m_acsManagerProxy = null;
            throw new RuntimeException("disconnected from the manager");
        }
    };
    ORB orb = acsCorba.getORB();
    m_managerClient = managerClientImpl._this(orb);
    m_acsManagerProxy = new AcsManagerProxy(m_managerLoc, orb, m_logger);
    m_acsManagerProxy.loginToManager(m_managerClient, 1);
}
Also used : ORB(org.omg.CORBA.ORB) AcsManagerProxy(alma.acs.container.AcsManagerProxy)

Example 4 with ORB

use of org.omg.CORBA.ORB 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)

Example 5 with ORB

use of org.omg.CORBA.ORB in project ACS by ACS-Community.

the class HibernateServer method run.

public void run(String[] args) {
    String iorFileName = null;
    final AcsLogger sharedLogger = AcsLoggerHelper.getInstance().getSharedLogger();
    try {
        Properties properties = System.getProperties();
        // default is JDK ORB
        boolean useJacORB = false;
        boolean profiler = false;
        int portNumber = Integer.parseInt(ACSPorts.getCDBPort());
        for (int i = 0; i < args.length; i++) {
            if (args[i].equals("-OAport") || args[i].equals("-OAPort")) {
                if (i < args.length - 1) {
                    portNumber = Integer.valueOf(args[++i]).intValue();
                }
            }
            if (args[i].equals("-OAIAddr")) {
                if (i < args.length - 1) {
                    properties.put("OAIAddr", args[++i]);
                }
            }
            if (args[i].equals("-orbacus")) {
                sharedLogger.log(AcsLogLevel.NOTICE, "ORBacus is no longer supported, switching to JacORB.");
                //System.err.println(
                //	"ORBacus is no longer supported, switching to JacORB.");
                useJacORB = true;
            }
            if (args[i].equals("-jacorb")) {
                useJacORB = true;
            }
            if (args[i].equals("-profiler")) {
                profiler = true;
            }
            if (args[i].equals("-o")) {
                if (i < args.length - 1) {
                    iorFileName = args[++i];
                } else {
                    iorFileName = "DAL.ior";
                }
            }
        }
        if (useJacORB) {
            if (Integer.getInteger("ACS.logstdout", 4) < 4) {
                sharedLogger.log(AcsLogLevel.INFO, "DALfs will use JacORB ORB");
            }
            properties.put("org.omg.CORBA.ORBClass", "org.jacorb.orb.ORB");
            properties.put("org.omg.CORBA.ORBSingletonClass", "org.jacorb.orb.ORBSingleton");
            // port
            properties.put("OAPort", Integer.toString(portNumber));
            // ORB implementation name
            properties.put("jacorb.implname", "ORB");
            /*
				 * by setting the following property, the ORB will
				 * accept client requests targeted at the object with
				 * key "CDB", so more readable corbaloc URLs
				 * can be used
				 */
            properties.put("jacorb.orb.objectKeyMap.CDB", "ORB/dalPOA/CDB");
        } else {
            properties.put("com.sun.CORBA.POA.ORBPersistentServerPort", Integer.toString(portNumber));
        }
        // create and initialize the ORB
        ORB orb = ORB.init(args, properties);
        // activate profiling
        if (orb instanceof AcsProfilingORB) {
            // This profiler will log ORB resource statistics every 10 seconds,
            // and will print every callback to requestStarted / requestFinished to stdout if the "-profiler" option is set (see above) 
            final boolean printIndividualCalls = profiler;
            AcsORBProfiler orbProfiler = new AcsORBProfilerImplBase(sharedLogger) {

                {
                    if (printIndividualCalls) {
                        debugRequestStarted = true;
                        debugRequestFinished = true;
                    }
                }
            };
            ((AcsProfilingORB) orb).registerAcsORBProfiler(orbProfiler);
        }
        // get reference to rootpoa & activate the POAManager
        POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        /* create a user defined poa for the naming contexts */
        org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
        policies[0] = rootpoa.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
        if (useJacORB)
            policies[1] = rootpoa.create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
        else
            policies[1] = rootpoa.create_lifespan_policy(LifespanPolicyValue.TRANSIENT);
        POA dalpoa = rootpoa.create_POA("dalPOA", rootpoa.the_POAManager(), policies);
        for (int i = 0; i < policies.length; i++) policies[i].destroy();
        rootpoa.the_POAManager().activate();
        // create servant and register it with the ORB
        //DALImpl DALImpl = new DALImpl(args, orb, dalpoa);
        //org.omg.PortableServer.Servant servant = new WDALImpl(args, orb, dalpoa);
        org.omg.PortableServer.Servant servant = new HibernateWDALImpl(args, orb, dalpoa, sharedLogger);
        //create object id
        byte[] id = { 'C', 'D', 'B' };
        //activate object
        dalpoa.activate_object_with_id(id, servant);
        // get object reference from the servant
        org.omg.CORBA.Object ref = dalpoa.servant_to_reference(servant);
        jdal = WDALHelper.narrow(ref);
        // try to bind it in IOR
        if (useJacORB) {
        // nothing to do here
        } else {
            ((com.sun.corba.se.internal.Interceptors.PIORB) orb).register_initial_reference("CDB", rootpoa.servant_to_reference(servant));
        }
        // register in name service if available
        try {
            // get the root naming context
            org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
            NamingContext ncRef = NamingContextHelper.narrow(objRef);
            // Bind the object reference in naming
            NameComponent nc = new NameComponent("CDB", "");
            NameComponent[] path = { nc };
            ncRef.rebind(path, jdal);
        } catch (Exception e1) {
            sharedLogger.log(AcsLogLevel.NOTICE, "JDAL is NOT registered in the name service because of: " + e1);
        }
        if (Integer.getInteger("ACS.logstdout", 4) < 4) {
            sharedLogger.log(AcsLogLevel.INFO, "JDAL is listening on " + ACSPorts.getIP() + ":" + portNumber + "/CDB");
        }
        // recover (notify) clients
        if (servant instanceof Recoverer) {
            ((Recoverer) servant).recoverClients();
        }
        if (iorFileName != null) {
            // write the object reference to a file
            PrintWriter iorFile = new PrintWriter(new FileWriter(iorFileName));
            iorFile.println(orb.object_to_string(jdal));
            iorFile.close();
        }
        sharedLogger.log(AcsLogLevel.INFO, "JDAL is ready and waiting ...");
        // GCH 2006-11-13
        // Here we put also a println to be sure that the message
        // ALWAYS appears on standart output, also if the logging level 
        // is put higher than INFO.
        // This is needed because the ACS startup scripts wait for this message
        // to declare complete the startup of the CDB. 
        System.out.println("JDAL is ready and waiting ...");
        // wait for invocations from clients
        orb.run();
        sharedLogger.log(AcsLogLevel.INFO, "JDAL exiting ORB loop ...");
    } catch (Exception e) {
        sharedLogger.log(AcsLogLevel.SEVERE, "Top level exception ", e);
    }
}
Also used : NameComponent(org.omg.CosNaming.NameComponent) FileWriter(java.io.FileWriter) Properties(java.util.Properties) NamingContext(org.omg.CosNaming.NamingContext) AcsORBProfiler(org.jacorb.orb.acs.AcsORBProfiler) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB) PrintWriter(java.io.PrintWriter) AcsORBProfilerImplBase(alma.acs.profiling.orb.AcsORBProfilerImplBase) POA(org.omg.PortableServer.POA) AcsProfilingORB(org.jacorb.orb.acs.AcsProfilingORB) ORB(org.omg.CORBA.ORB) AcsLogger(alma.acs.logging.AcsLogger)

Aggregations

ORB (org.omg.CORBA.ORB)74 POA (org.omg.PortableServer.POA)12 Properties (java.util.Properties)10 NamingException (javax.naming.NamingException)8 Test (org.junit.Test)7 IOException (java.io.IOException)6 AcsProfilingORB (org.jacorb.orb.acs.AcsProfilingORB)6 Logger (java.util.logging.Logger)5 Any (org.omg.CORBA.Any)5 HashMap (java.util.HashMap)4 StartException (org.jboss.msc.service.StartException)4 ManagerImpl (com.cosylab.acs.maci.manager.ManagerImpl)3 FileWriter (java.io.FileWriter)3 PrintWriter (java.io.PrintWriter)3 MessageImpl (org.apache.cxf.message.MessageImpl)3 Monitorlong (alma.ACS.Monitorlong)2 DAL (com.cosylab.CDB.DAL)2 HandleDataStore (com.cosylab.acs.maci.manager.HandleDataStore)2 EstablishContext (com.sun.corba.ee.org.omg.CSI.EstablishContext)2 SASContextBody (com.sun.corba.ee.org.omg.CSI.SASContextBody)2