private ActionResponse executeAction(IAction action) throws CapabilityException { ActionResponse response; try { IProtocolManager protocolManager = Activator.getProtocolManagerService(); IProtocolSessionManager protocolSessionManager = protocolManager.getProtocolSessionManager(this.resourceId); response = action.execute(protocolSessionManager); } catch (ProtocolException pe) { log.error("Error with protocol session - " + pe.getMessage()); throw new CapabilityException(pe); } catch (ActivatorException ae) { String errorMsg = "Error getting protocol manager - " + ae.getMessage(); log.error(errorMsg); throw new CapabilityException(errorMsg, ae); } catch (ActionException ae) { log.error("Error executing " + action.getActionID() + " action - " + ae.getMessage()); throw (ae); } if (!response.getStatus().equals(ActionResponse.STATUS.OK)) { String errMsg = "Error executing " + action.getActionID() + " action - " + response.getInformation(); log.error(errMsg); throw new ActionException(errMsg); } return response; }
@BeforeClass public static void init() { setEncapsulationAction = new SetTaggedEthernetEncapsulationAction(); removeEncapsulationAction = new RemoveTaggedEthernetEncapsulationAction(); setVlanAction = new SetVlanIdAction(); setEncapsulationAction.setModelToUpdate(new ComputerSystem()); removeEncapsulationAction.setModelToUpdate(new ComputerSystem()); setVlanAction.setModelToUpdate(new ComputerSystem()); protocolManager = new ProtocolManager(); try { protocolSessionManager = (ProtocolSessionManager) protocolManager.getProtocolSessionManager(resourceId); protocolSessionManager.setEventManager(new MockEventManager()); netconfContext = newSessionContextNetconf(); protocolManager.sessionFactoryAdded( new NetconfProtocolSessionFactory(), new HashMap<String, String>() { { put(ProtocolSessionContext.PROTOCOL, "netconf"); } }); protocolSessionManager.registerContext(netconfContext); } catch (ProtocolException e) { e.printStackTrace(); } }