Search in sources :

Example 1 with LookupManager

use of org.cristalise.kernel.lookup.LookupManager in project kernel by cristal-ise.

the class Bootstrap method verifyPathAndModuleProperty.

/**
 * Verify module property and location
 *
 * @param ns
 * @param itemType
 * @param itemName
 * @param itemPath
 * @param modDomPath
 * @param path
 * @return the ItemProxy either create or initialised for existing
 * @throws Exception
 */
private static ItemProxy verifyPathAndModuleProperty(String ns, String itemType, String itemName, ItemPath itemPath, DomainPath modDomPath, DomainPath path) throws Exception {
    LookupManager lookupManager = Gateway.getLookupManager();
    ItemProxy thisProxy = Gateway.getProxyManager().getProxy(path);
    if (itemPath != null && !path.getItemPath().equals(itemPath)) {
        Logger.warning("Resource " + itemType + "/" + itemName + " should have path " + itemPath + " but was found with path " + path.getItemPath());
        itemPath = path.getItemPath();
    }
    if (itemPath == null)
        itemPath = path.getItemPath();
    String moduleName = (ns == null ? "kernel" : ns);
    String itemModule;
    try {
        itemModule = thisProxy.getProperty("Module");
        if (itemModule != null && !itemModule.equals("") && !itemModule.equals("null") && !moduleName.equals(itemModule)) {
            String error = "Module clash! Resource '" + itemName + "' included in module " + moduleName + " but is assigned to '" + itemModule + "'.";
            Logger.error(error);
            throw new InvalidDataException(error);
        }
    } catch (ObjectNotFoundException ex) {
        itemModule = "";
    }
    if (!modDomPath.equals(path)) {
        // move item to module subtree
        Logger.msg("Module item " + itemName + " found with path " + path.toString() + ". Moving to " + modDomPath.toString());
        modDomPath.setItemPath(itemPath);
        if (!modDomPath.exists())
            lookupManager.add(modDomPath);
        lookupManager.delete(path);
    }
    return thisProxy;
}
Also used : ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException)

Example 2 with LookupManager

use of org.cristalise.kernel.lookup.LookupManager in project kernel by cristal-ise.

the class Bootstrap method createResourceItem.

/**
 * @param impHandler
 * @param itemName
 * @param ns
 * @param itemPath
 * @return the ItemProxy representing the newly create Item
 * @throws Exception
 */
private static ItemProxy createResourceItem(ResourceImportHandler impHandler, String itemName, String ns, ItemPath itemPath) throws Exception {
    // create props
    PropertyDescriptionList pdList = impHandler.getPropDesc();
    PropertyArrayList props = new PropertyArrayList();
    LookupManager lookupManager = Gateway.getLookupManager();
    for (int i = 0; i < pdList.list.size(); i++) {
        PropertyDescription pd = pdList.list.get(i);
        String propName = pd.getName();
        String propVal = pd.getDefaultValue();
        if (propName.equals(NAME.toString()))
            propVal = itemName;
        else if (propName.equals(MODULE.toString()))
            propVal = (ns == null) ? "kernel" : ns;
        props.list.add(new Property(propName, propVal, pd.getIsMutable()));
    }
    CompositeActivity ca = new CompositeActivity();
    try {
        ca = (CompositeActivity) ((CompositeActivityDef) LocalObjectLoader.getActDef(impHandler.getWorkflowName(), 0)).instantiate();
    } catch (ObjectNotFoundException ex) {
        Logger.error(ex);
        Logger.error("Module resource workflow " + impHandler.getWorkflowName() + " not found. Using empty.");
    }
    Gateway.getCorbaServer().createItem(itemPath);
    lookupManager.add(itemPath);
    DomainPath newDomPath = impHandler.getPath(itemName, ns);
    newDomPath.setItemPath(itemPath);
    lookupManager.add(newDomPath);
    ItemProxy newItemProxy = Gateway.getProxyManager().getProxy(itemPath);
    newItemProxy.initialise(systemAgents.get("system").getPath(), props, ca, null);
    return newItemProxy;
}
Also used : PropertyDescription(org.cristalise.kernel.property.PropertyDescription) DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) CompositeActivity(org.cristalise.kernel.lifecycle.instance.CompositeActivity) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) PropertyArrayList(org.cristalise.kernel.property.PropertyArrayList) CompositeActivityDef(org.cristalise.kernel.lifecycle.CompositeActivityDef) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) Property(org.cristalise.kernel.property.Property) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint)

Example 3 with LookupManager

use of org.cristalise.kernel.lookup.LookupManager in project kernel by cristal-ise.

the class Gateway method startServer.

/**
 * Makes this process capable of creating and managing server entities. Runs the
 * Creates the LookupManager, ProxyServer, initialises the ORB and CORBAServer
 */
public static void startServer() throws InvalidDataException, CannotManageException {
    try {
        // check top level directory contexts
        if (mLookup instanceof LookupManager) {
            mLookupManager = (LookupManager) mLookup;
            mLookupManager.initializeDirectory();
        } else {
            throw new CannotManageException("Lookup implementation is not a LookupManager. Cannot write to directory");
        }
        // start entity proxy server
        mProxyServer = new ProxyServer(mC2KProps.getProperty("ItemServer.name"));
        // Init ORB - set various config
        String serverName = mC2KProps.getProperty("ItemServer.name");
        // TODO: externalize this (or replace corba completely)
        if (serverName != null)
            mC2KProps.put("com.sun.CORBA.ORBServerHost", serverName);
        String serverPort = mC2KProps.getProperty("ItemServer.iiop", "1500");
        mC2KProps.put("com.sun.CORBA.ORBServerPort", serverPort);
        mC2KProps.put("com.sun.CORBA.POA.ORBServerId", "1");
        mC2KProps.put("com.sun.CORBA.POA.ORBPersistentServerPort", serverPort);
        // need to force UTF-8 in the Sun ORB
        mC2KProps.put("com.sun.CORBA.codeset.charsets", "0x05010001, 0x00010109");
        mC2KProps.put("com.sun.CORBA.codeset.wcharsets", "0x00010109, 0x05010001");
        // Standard initialisation of the ORB
        orbDestroyed = false;
        mORB = org.omg.CORBA.ORB.init(new String[0], mC2KProps);
        Logger.msg("Gateway.startServer() - ORB initialised. ORB class:'" + mORB.getClass().getName() + "'");
        // start corba server components
        mCorbaServer = new CorbaServer();
        Logger.msg("Gateway.startServer() - Server '" + serverName + "' STARTED.");
    } catch (Exception ex) {
        Logger.error(ex);
        Logger.die("Exception starting server components. Shutting down.");
    }
}
Also used : CannotManageException(org.cristalise.kernel.common.CannotManageException) LookupManager(org.cristalise.kernel.lookup.LookupManager) CorbaServer(org.cristalise.kernel.entity.CorbaServer) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) MalformedURLException(java.net.MalformedURLException) PersistencyException(org.cristalise.kernel.common.PersistencyException) CannotManageException(org.cristalise.kernel.common.CannotManageException) ProxyServer(org.cristalise.kernel.entity.proxy.ProxyServer)

Example 4 with LookupManager

use of org.cristalise.kernel.lookup.LookupManager in project kernel by cristal-ise.

the class RemoveRole method runActivityLogic.

@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, CannotManageException, ObjectNotFoundException, ObjectCannotBeUpdated {
    String[] params = getDataList(requestData);
    Logger.msg(3, "RemoveRole: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    if (params.length != 1)
        throw new InvalidDataException("RemoveRole must have one paramater:" + Arrays.toString(params));
    LookupManager lookup = Gateway.getLookupManager();
    RolePath thisRole = lookup.getRolePath(params[0]);
    AgentPath[] agents = Gateway.getLookup().getAgents(thisRole);
    if (agents.length > 0)
        throw new ObjectCannotBeUpdated("Cannot remove role as " + agents.length + " other agents still hold it.");
    lookup.delete(thisRole);
    return requestData;
}
Also used : AgentPath(org.cristalise.kernel.lookup.AgentPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectCannotBeUpdated(org.cristalise.kernel.common.ObjectCannotBeUpdated) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 5 with LookupManager

use of org.cristalise.kernel.lookup.LookupManager in project kernel by cristal-ise.

the class Bootstrap method createServerItem.

public static void createServerItem() throws Exception {
    LookupManager lookupManager = Gateway.getLookupManager();
    String serverName = Gateway.getProperties().getString("ItemServer.name", InetAddress.getLocalHost().getHostName());
    thisServerPath = new DomainPath("/servers/" + serverName);
    ItemPath serverItem;
    try {
        serverItem = thisServerPath.getItemPath();
    } catch (ObjectNotFoundException ex) {
        Logger.msg("Creating server item " + thisServerPath);
        serverItem = new ItemPath();
        Gateway.getCorbaServer().createItem(serverItem);
        lookupManager.add(serverItem);
        thisServerPath.setItemPath(serverItem);
        lookupManager.add(thisServerPath);
    }
    int proxyPort = Gateway.getProperties().getInt("ItemServer.Proxy.port", 1553);
    Gateway.getStorage().put(serverItem, new Property(NAME, serverName, false), null);
    Gateway.getStorage().put(serverItem, new Property(TYPE, "Server", false), null);
    Gateway.getStorage().put(serverItem, new Property(KERNEL_VERSION, Gateway.getKernelVersion(), true), null);
    Gateway.getStorage().put(serverItem, new Property("ProxyPort", String.valueOf(proxyPort), false), null);
    Gateway.getStorage().put(serverItem, new Property("ConsolePort", String.valueOf(Logger.getConsolePort()), true), null);
    Gateway.getProxyManager().connectToProxyServer(serverName, proxyPort);
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) LookupManager(org.cristalise.kernel.lookup.LookupManager) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Property(org.cristalise.kernel.property.Property) Viewpoint(org.cristalise.kernel.persistency.outcome.Viewpoint) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Aggregations

LookupManager (org.cristalise.kernel.lookup.LookupManager)6 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)5 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)4 Property (org.cristalise.kernel.property.Property)3 PersistencyException (org.cristalise.kernel.common.PersistencyException)2 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)2 AgentPath (org.cristalise.kernel.lookup.AgentPath)2 DomainPath (org.cristalise.kernel.lookup.DomainPath)2 ItemPath (org.cristalise.kernel.lookup.ItemPath)2 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)2 MalformedURLException (java.net.MalformedURLException)1 CannotManageException (org.cristalise.kernel.common.CannotManageException)1 ObjectCannotBeUpdated (org.cristalise.kernel.common.ObjectCannotBeUpdated)1 CorbaServer (org.cristalise.kernel.entity.CorbaServer)1 AgentProxy (org.cristalise.kernel.entity.proxy.AgentProxy)1 ProxyServer (org.cristalise.kernel.entity.proxy.ProxyServer)1 CompositeActivityDef (org.cristalise.kernel.lifecycle.CompositeActivityDef)1 CompositeActivity (org.cristalise.kernel.lifecycle.instance.CompositeActivity)1 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)1 RolePath (org.cristalise.kernel.lookup.RolePath)1