Search in sources :

Example 21 with DomainPath

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

the class StandardServer method standardInitialisation.

/**
 * Initialise the server
 *
 * @param props initiliased Properties
 * @param res the instantiated ResourceLoader
 * @throws Exception throw whatever happens
 */
public static void standardInitialisation(Properties props, ResourceLoader res) throws Exception {
    isServer = true;
    // read args and init Gateway
    Gateway.init(props, res);
    // connect to LDAP as root
    Gateway.connect();
    // start console
    Logger.initConsole("ItemServer");
    // initialize the server objects
    Gateway.startServer();
    if (Gateway.getProperties().containsKey(AbstractMain.MAIN_ARG_RESETIOR)) {
        Logger.msg(5, "StandardServer.standardInitialisation() - RESETTING IORs");
        resetItemIORs(new DomainPath(""));
        resetAgentIORs(new RolePath());
        AbstractMain.shutdown(0);
    } else {
        // start checking bootstrap & module items
        Bootstrap.run();
    }
    Logger.msg(5, "StandardServer.standardInitialisation() - complete.");
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) RolePath(org.cristalise.kernel.lookup.RolePath)

Example 22 with DomainPath

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

the class StandardServer method resetItemIORs.

public static void resetItemIORs(DomainPath root) throws ObjectNotFoundException, ObjectCannotBeUpdated, CannotManageException {
    Logger.msg("StandardServer.resetItemIORs() - root:" + root);
    Iterator<Path> pathes = Gateway.getLookup().getChildren(root);
    while (pathes.hasNext()) {
        DomainPath domain = (DomainPath) pathes.next();
        if (domain.isContext()) {
            resetItemIORs(domain);
        } else {
            Logger.msg("StandardServer.resetItemIORs() - setting IOR for domain:" + domain + " item:" + domain.getItemPath());
            Gateway.getLookupManager().setIOR(domain.getItemPath(), Gateway.getORB().object_to_string(Gateway.getCorbaServer().getItemIOR(domain.getItemPath())));
        }
    }
}
Also used : RolePath(org.cristalise.kernel.lookup.RolePath) DomainPath(org.cristalise.kernel.lookup.DomainPath) Path(org.cristalise.kernel.lookup.Path) AgentPath(org.cristalise.kernel.lookup.AgentPath) DomainPath(org.cristalise.kernel.lookup.DomainPath)

Example 23 with DomainPath

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

the class AddNewSlot method runActivityLogic.

/**
 * Creates a new slot in the given aggregation, that holds instances of the given item description
 *
 * Params:
 * <ol>
 * <li>Collection name</li>
 * <li>Item Description key (optional)</li>
 * <li>Item Description version (optional)</li>
 * </ol>
 *
 * @throws InvalidDataException
 *             Then the parameters were incorrect
 * @throws PersistencyException
 *             There was a problem loading or saving the collection from persistency
 * @throws ObjectNotFoundException
 *             A required object, such as the collection or a PropertyDescription outcome, wasn't found
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, PersistencyException, ObjectNotFoundException {
    String collName;
    ItemPath descKey = null;
    String descVer = "last";
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "AddNewSlot: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    // resolve desc item path and version
    try {
        collName = params[0];
        if (params.length > 1 && params[1].length() > 0) {
            try {
                descKey = new ItemPath(params[1]);
            } catch (InvalidItemPathException e) {
                descKey = new DomainPath(params[1]).getItemPath();
            }
        }
        if (params.length > 2 && params[2].length() > 0)
            descVer = params[2];
    } catch (Exception e) {
        throw new InvalidDataException("AddNewSlot: Invalid parameters " + Arrays.toString(params));
    }
    // load collection
    C2KLocalObject collObj = Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    if (!(collObj instanceof Aggregation))
        throw new InvalidDataException("AddNewSlot operates on Aggregation only.");
    Aggregation agg = (Aggregation) collObj;
    // get props
    CastorHashMap props = new CastorHashMap();
    StringBuffer classProps = new StringBuffer();
    if (descKey != null) {
        PropertyDescriptionList propList;
        propList = PropertyUtility.getPropertyDescriptionOutcome(descKey, descVer, locker);
        for (PropertyDescription pd : propList.list) {
            props.put(pd.getName(), pd.getDefaultValue());
            if (pd.getIsClassIdentifier())
                classProps.append((classProps.length() > 0 ? "," : "")).append(pd.getName());
        }
    }
    agg.addSlot(props, classProps.toString());
    Gateway.getStorage().put(item, agg, locker);
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) Aggregation(org.cristalise.kernel.collection.Aggregation) PropertyDescription(org.cristalise.kernel.property.PropertyDescription) C2KLocalObject(org.cristalise.kernel.entity.C2KLocalObject) CastorHashMap(org.cristalise.kernel.utils.CastorHashMap) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PropertyDescriptionList(org.cristalise.kernel.property.PropertyDescriptionList) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 24 with DomainPath

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

the class RemoveSlotFromCollection method runActivityLogic.

/**
 * Params: 0 - collection name 1 - slot number OR if -1: 2 - target entity key
 *
 * @throws ObjectNotFoundException
 * @throws PersistencyException
 */
@Override
protected String runActivityLogic(AgentPath agent, ItemPath item, int transitionID, String requestData, Object locker) throws InvalidDataException, ObjectNotFoundException, PersistencyException {
    String collName;
    int slotNo = -1;
    ItemPath currentChild = null;
    Collection<? extends CollectionMember> coll;
    // extract parameters
    String[] params = getDataList(requestData);
    if (Logger.doLog(3))
        Logger.msg(3, "RemoveSlotFromCollection: called by " + agent + " on " + item + " with parameters " + Arrays.toString(params));
    try {
        collName = params[0];
        if (params.length > 1 && params[1].length() > 0)
            slotNo = Integer.parseInt(params[1]);
        if (params.length > 2 && params[2].length() > 0) {
            try {
                currentChild = new ItemPath(params[2]);
            } catch (InvalidItemPathException e) {
                currentChild = new DomainPath(params[2]).getItemPath();
            }
        }
    } catch (Exception e) {
        throw new InvalidDataException("RemoveSlotFromCollection: Invalid parameters " + Arrays.toString(params));
    }
    if (slotNo == -1 && currentChild == null)
        throw new InvalidDataException("RemoveSlotFromCollection: Must give either slot number or item UUID");
    // load collection
    try {
        coll = (Collection<? extends CollectionMember>) Gateway.getStorage().get(item, ClusterType.COLLECTION + "/" + collName + "/last", locker);
    } catch (PersistencyException ex) {
        Logger.error(ex);
        throw new PersistencyException("RemoveSlotFromCollection: Error loading collection '\"+collName+\"': " + ex.getMessage());
    }
    // check the slot is there if it's given by id
    CollectionMember slot = null;
    if (slotNo > -1) {
        slot = coll.getMember(slotNo);
    }
    // if both parameters are supplied, check the given item is actually in that slot
    if (slot != null && currentChild != null && !slot.getItemPath().equals(currentChild)) {
        throw new ObjectNotFoundException("RemoveSlotFromCollection: Item " + currentChild + " was not in slot " + slotNo);
    }
    if (slotNo == -1) {
        // find slot from entity key
        for (CollectionMember member : coll.getMembers().list) {
            if (member.getItemPath().equals(currentChild)) {
                slotNo = member.getID();
                break;
            }
        }
    }
    if (slotNo == -1) {
        throw new ObjectNotFoundException("Could not find " + currentChild + " in collection " + coll.getName());
    }
    // Remove the slot
    coll.removeMember(slotNo);
    // Store the collection
    try {
        Gateway.getStorage().put(item, coll, locker);
    } catch (PersistencyException e) {
        Logger.error(e);
        throw new PersistencyException("Error storing collection");
    }
    return requestData;
}
Also used : InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) DomainPath(org.cristalise.kernel.lookup.DomainPath) CollectionMember(org.cristalise.kernel.collection.CollectionMember) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) PersistencyException(org.cristalise.kernel.common.PersistencyException) InvalidItemPathException(org.cristalise.kernel.lookup.InvalidItemPathException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ItemPath(org.cristalise.kernel.lookup.ItemPath)

Example 25 with DomainPath

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

the class ModuleManager method registerModules.

public void registerModules() throws ModuleException {
    ItemProxy serverItem;
    try {
        serverItem = Gateway.getProxyManager().getProxy(new DomainPath("/servers/" + Gateway.getProperties().getString("ItemServer.name")));
    } catch (ObjectNotFoundException e) {
        throw new ModuleException("Cannot find local server name.");
    }
    Logger.msg(3, "ModuleManager.registerModules() - Registering modules");
    boolean reset = Gateway.getProperties().getBoolean("Module.reset", false);
    for (Module thisMod : modules) {
        if (Bootstrap.shutdown)
            return;
        Logger.msg("ModuleManager.registerModules() - Registering module " + thisMod.getName());
        try {
            String thisResetKey = "Module." + thisMod.getNamespace() + ".reset";
            boolean thisReset = reset;
            if (Gateway.getProperties().containsKey(thisResetKey)) {
                thisReset = Gateway.getProperties().getBoolean(thisResetKey);
            }
            thisMod.setModuleXML(modulesXML.get(thisMod.getNamespace()));
            thisMod.importAll(serverItem, agent, thisReset);
        } catch (Exception e) {
            Logger.error(e);
            throw new ModuleException("Error importing items for module " + thisMod.getName());
        }
        Logger.msg("ModuleManager.registerModules() - Module " + thisMod.getName() + " registered");
        try {
            thisMod.runScript("startup", agent, true);
        } catch (ScriptingEngineException e) {
            Logger.error(e);
            throw new ModuleException("Error in startup script for module " + thisMod.getName());
        }
    }
}
Also used : DomainPath(org.cristalise.kernel.lookup.DomainPath) ItemProxy(org.cristalise.kernel.entity.proxy.ItemProxy) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) InvalidDataException(org.cristalise.kernel.common.InvalidDataException) ObjectNotFoundException(org.cristalise.kernel.common.ObjectNotFoundException) ScriptingEngineException(org.cristalise.kernel.scripting.ScriptingEngineException)

Aggregations

DomainPath (org.cristalise.kernel.lookup.DomainPath)26 ItemPath (org.cristalise.kernel.lookup.ItemPath)15 ObjectNotFoundException (org.cristalise.kernel.common.ObjectNotFoundException)12 InvalidDataException (org.cristalise.kernel.common.InvalidDataException)11 InvalidItemPathException (org.cristalise.kernel.lookup.InvalidItemPathException)8 ObjectAlreadyExistsException (org.cristalise.kernel.common.ObjectAlreadyExistsException)5 PersistencyException (org.cristalise.kernel.common.PersistencyException)5 C2KLocalObject (org.cristalise.kernel.entity.C2KLocalObject)4 Property (org.cristalise.kernel.property.Property)4 PropertyArrayList (org.cristalise.kernel.property.PropertyArrayList)4 PropertyDescription (org.cristalise.kernel.property.PropertyDescription)4 PropertyDescriptionList (org.cristalise.kernel.property.PropertyDescriptionList)4 Aggregation (org.cristalise.kernel.collection.Aggregation)3 TraceableEntity (org.cristalise.kernel.entity.TraceableEntity)3 ItemProxy (org.cristalise.kernel.entity.proxy.ItemProxy)3 AgentPath (org.cristalise.kernel.lookup.AgentPath)3 Path (org.cristalise.kernel.lookup.Path)3 Outcome (org.cristalise.kernel.persistency.outcome.Outcome)3 Viewpoint (org.cristalise.kernel.persistency.outcome.Viewpoint)3 Test (org.junit.Test)3