package com.c2kernel.lifecycle.instance.predefined.server; import com.c2kernel.common.AccessRightsException; import com.c2kernel.common.InvalidDataException; import com.c2kernel.common.InvalidTransitionException; import com.c2kernel.common.ObjectCannotBeUpdated; import com.c2kernel.common.ObjectNotFoundException; import com.c2kernel.lifecycle.instance.predefined.PredefinedStep; import com.c2kernel.lookup.AgentPath; import com.c2kernel.lookup.RolePath; import com.c2kernel.persistency.ClusterStorageException; import com.c2kernel.process.Gateway; import com.c2kernel.utils.Logger; public class RemoveAgent extends PredefinedStep { public RemoveAgent() { super(); } @Override public void request(AgentPath agent, int transitionID, String requestData) throws AccessRightsException, InvalidTransitionException, InvalidDataException { Logger.msg(1, "RemoveAgent::request() - Starting."); checkAccessRights(agent); String[] params = getDataList(requestData); AgentPath targetAgent; try { targetAgent = Gateway.getLDAPLookup().getRoleManager().getAgentPath(params[0]); } catch (ObjectNotFoundException e) { throw new InvalidDataException("Agent "+params[0]+" not found", ""); } //remove from roles for (RolePath role: targetAgent.getRoles()) { try { role.removeAgent(targetAgent); } catch (ObjectCannotBeUpdated e) { Logger.error(e); throw new InvalidDataException("Error removing "+params[0]+" from Role "+role.getName(), ""); } catch (ObjectNotFoundException e) { Logger.error(e); throw new InvalidDataException("Tried to remove "+params[0]+" from Role "+role.getName()+" that doesn't exist.", ""); } } //clear out all storages try { Gateway.getStorage().removeCluster(targetAgent.getSysKey(), "", null); } catch (ClusterStorageException e) { Logger.error(e); throw new InvalidDataException("Error deleting storage for "+params[0], ""); } //remove entity path try { Gateway.getLDAPLookup().delete(targetAgent); } catch (ObjectCannotBeUpdated e) { throw new InvalidDataException("Error deleting AgentPath for "+params[0], ""); } sendEventStoreOutcome(transitionID, requestData, agent); } }