From 275d0bbf555c8917be82ce4cc21eb4cabb00f4c5 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Fri, 3 Oct 2014 17:30:41 +0200 Subject: Huge exception overhaul: Merged ClusterStorageException with PersistencyException. Replaced MembershipException with InvalidCollectionModification CORBA Exception. Made all predef steps throw more accurate exceptions when they go wrong, and let more exceptions bubble through from underneath. --- .../agent/CreateAgentFromDescription.java | 123 ++++++++++++--------- .../instance/predefined/agent/RemoveAgent.java | 28 ++--- .../predefined/agent/SetAgentPassword.java | 33 ++---- .../instance/predefined/agent/SetAgentRoles.java | 16 +-- 4 files changed, 102 insertions(+), 98 deletions(-) (limited to 'src/main/java/com/c2kernel/lifecycle/instance/predefined/agent') diff --git a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java index 0ce7c67..564c5db 100644 --- a/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java +++ b/src/main/java/com/c2kernel/lifecycle/instance/predefined/agent/CreateAgentFromDescription.java @@ -20,10 +20,14 @@ */ package com.c2kernel.lifecycle.instance.predefined.agent; -import com.c2kernel.common.AccessRightsException; -import com.c2kernel.common.InvalidDataException; -import com.c2kernel.common.ObjectAlreadyExistsException; -import com.c2kernel.common.ObjectNotFoundException; +import java.util.Arrays; + +import com.c2kernel.common.CannotManage; +import com.c2kernel.common.InvalidData; +import com.c2kernel.common.ObjectAlreadyExists; +import com.c2kernel.common.ObjectCannotBeUpdated; +import com.c2kernel.common.ObjectNotFound; +import com.c2kernel.common.PersistencyException; import com.c2kernel.entity.CorbaServer; import com.c2kernel.entity.agent.ActiveEntity; import com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription; @@ -53,71 +57,80 @@ public class CreateAgentFromDescription extends CreateItemFromDescription *
  • Comma-delimited Role names to assign to the agent. Must already exist.
  • *
  • Initial properties to set in the new Agent
  • * + * @throws ObjectNotFound + * @throws InvalidData The input parameters were incorrect + * @throws ObjectAlreadyExists The Agent already exists + * @throws CannotManage The Agent could not be created + * @throws ObjectCannotBeUpdated The addition of the new entries into the LookupManager failed * @see com.c2kernel.lifecycle.instance.predefined.item.CreateItemFromDescription#runActivityLogic(com.c2kernel.lookup.AgentPath, int, int, java.lang.String) */ @Override - protected String runActivityLogic(AgentPath agent, ItemPath itemPath, - int transitionID, String requestData) throws InvalidDataException { + protected String runActivityLogic(AgentPath agent, ItemPath item, + int transitionID, String requestData) throws ObjectNotFound, InvalidData, ObjectAlreadyExists, CannotManage, ObjectCannotBeUpdated { + + String[] params = getDataList(requestData); + if (Logger.doLog(3)) Logger.msg(3, "CreateAgentFromDescription: called by "+agent+" on "+item+" with parameters "+Arrays.toString(params)); + if (params.length < 3 || params.length > 4) + throw new InvalidData("CreateAgentFromDescription: Invalid parameters "+Arrays.toString(params)); - String[] input = getDataList(requestData); - String newName = input[0]; - String descVer = input[1]; - String roles = input[2]; + String newName = params[0]; + String descVer = params[1]; + String roles = params[2]; PropertyArrayList initProps = - input.length > 3 ? getInitProperties(input[3]):new PropertyArrayList(); + params.length > 3 ? getInitProperties(params[3]):new PropertyArrayList(); Logger.msg(1, "CreateAgentFromDescription::request() - Starting."); - try { - - // check if given roles exist - String[] roleArr = roles.split(","); - for(int i=0; i rolesToRemove = new ArrayList(); @@ -75,7 +75,7 @@ public class SetAgentRoles extends PredefinedStep { Gateway.getLookupManager().removeRole(targetAgent, roleToRemove); } catch (Exception e) { Logger.error(e); - throw new InvalidDataException("Error removing role "+roleToRemove.getName(), ""); + throw new InvalidData("Error removing role "+roleToRemove.getName()); } // add requested roles we don't already have @@ -84,7 +84,7 @@ public class SetAgentRoles extends PredefinedStep { Gateway.getLookupManager().addRole(targetAgent, roleToAdd); } catch (Exception e) { Logger.error(e); - throw new InvalidDataException("Error adding role "+roleToAdd.getName(), ""); + throw new InvalidData("Error adding role "+roleToAdd.getName()); } return requestData; -- cgit v1.2.3