@Test public void testAssociationCommands() throws Exception { String sctpAssocCommand = "sctp association create Assoc1 CLIENT 127.0.0.1 2905 127.0.0.1 2906"; String result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, "Assoc1", this.management1.getName())); assertEquals(1, this.management1.getAssociations().size()); assertEquals(0, this.management2.getAssociations().size()); sctpAssocCommand = "sctp association create Assoc2 CLIENT 127.0.0.1 2907 127.0.0.1 2908 stackname TestSCTP2"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, "Assoc2", this.management2.getName())); assertEquals(1, this.management1.getAssociations().size()); assertEquals(1, this.management2.getAssociations().size()); String sctpServerCommand = "sctp server create TestServer1 127.0.0.1 2903 stackname TestSCTP1"; result = this.sctpShellExecutor.execute(sctpServerCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.ADD_SERVER_SUCCESS, "TestServer1", this.management1.getName())); sctpAssocCommand = "sctp association create Assoc3 SERVER TestServer1 192.168.56.1 2905"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.ADD_SERVER_ASSOCIATION_SUCCESS, "Assoc3", this.management1.getName())); assertEquals(2, this.management1.getAssociations().size()); assertEquals(1, this.management2.getAssociations().size()); sctpAssocCommand = "sctp association show"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); System.out.println(result); assertTrue(result.contains("Assoc1") && result.contains("Assoc3")); assertFalse(result.contains("Assoc2")); sctpAssocCommand = "sctp association show stackname TestSCTP2"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); System.out.println(result); assertTrue(result.contains("Assoc2")); assertFalse(result.contains("Assoc1") || result.contains("Assoc3")); sctpAssocCommand = "sctp association destroy Assoc2"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, "Assoc2", this.management2.getName())); assertEquals(2, this.management1.getAssociations().size()); assertEquals(0, this.management2.getAssociations().size()); sctpAssocCommand = "sctp association destroy Assoc1 stackname TestSCTP1"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, "Assoc1", this.management1.getName())); assertEquals(1, this.management1.getAssociations().size()); assertEquals(0, this.management2.getAssociations().size()); sctpAssocCommand = "sctp association destroy Assoc3 stackname TestSCTP1"; result = this.sctpShellExecutor.execute(sctpAssocCommand.split(" ")); assertEquals(result, String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, "Assoc3", this.management1.getName())); assertEquals(0, this.management1.getAssociations().size()); assertEquals(0, this.management2.getAssociations().size()); }
@Override public String execute(String[] args) { try { if (this.sctpManagements.size() == 0) { return M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN; } if (args.length < 2 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1] == null) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1].equals("server")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 6 || args.length > 10) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String hostAddress = args[4]; if (hostAddress == null) { return M3UAOAMMessages.INVALID_COMMAND; } String[] hostAddresses = hostAddress.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[5]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 6; if (args.length > 6) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServer(serverName, primaryAddress, hostPort, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("modify")) { String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String hostAddress = null; Integer port = null; IpChannelType ipChannelType = null; Boolean acceptAnonymousConnections = null; Integer maxConcurrentConnectionsCount = null; String[] extraHostAddresses = null; int i = 5; if (args.length > 5) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "host": hostAddress = args[i + 1]; break; case "port": port = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "anonymconnect": acceptAnonymousConnections = Boolean.valueOf(args[i + 1]); break; case "concurrentconnect": maxConcurrentConnectionsCount = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServer(serverName, hostAddress, port, ipChannelType, acceptAnonymousConnections, maxConcurrentConnectionsCount, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeServer(serverName); return String.format(SCTPOAMMessages.REMOVE_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("start")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.startServer(serverName); return String.format(SCTPOAMMessages.START_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("stop")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.stopServer(serverName); return String.format(SCTPOAMMessages.STOP_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showServers(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("association")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 8 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String type = args[4]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { if (args.length < 9) { return M3UAOAMMessages.INVALID_COMMAND; } String peerIp = args[5]; int peerPort = Integer.parseInt(args[6]); String hostIp = args[7]; String[] hostAddresses = hostIp.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[8]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 9; if (args.length > 9) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addAssociation(primaryAddress, hostPort, peerIp, peerPort, assocName, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String serverName = args[5]; String peerIp = args[6]; int peerPort = Integer.parseInt(args[7]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 8; if (args.length > 8) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } if (this.sctpManagement == null) { this.setDefaultValue(); } if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServerAssociation(peerIp, peerPort, serverName, assocName, ipChnnelType); return String.format(SCTPOAMMessages.ADD_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("modify")) { String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String type = args[5]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { String hostAddress = null; Integer hostPort = null; String peerAddress = null; Integer peerPort = null; IpChannelType ipChannelType = null; String[] extraHostAddresses = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "host": hostAddress = args[i + 1]; break; case "port": hostPort = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyAssociation(hostAddress, hostPort, peerAddress, peerPort, assocName, ipChannelType, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String peerAddress = null; Integer peerPort = null; String serverName = null; IpChannelType ipChannelType = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "servername": serverName = args[i + 1]; break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServerAssociation(assocName, peerAddress, peerPort, serverName, ipChannelType); return String.format(SCTPOAMMessages.MODIFY_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeAssociation(assocName); return String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showAssociations(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("set")) { return this.manageSet(args); } else if (args[1].equals("get")) { return this.manageGet(args); } return M3UAOAMMessages.INVALID_COMMAND; } catch (Exception e) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), e); return e.toString(); } catch (Throwable t) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), t); return t.toString(); } }
SCTPShellExecutor implements ShellExecutor { @Override public String execute(String[] args) { try { if (this.sctpManagements.size() == 0) { return M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN; } if (args.length < 2 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1] == null) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1].equals("server")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 6 || args.length > 10) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String hostAddress = args[4]; if (hostAddress == null) { return M3UAOAMMessages.INVALID_COMMAND; } String[] hostAddresses = hostAddress.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[5]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 6; if (args.length > 6) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServer(serverName, primaryAddress, hostPort, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("modify")) { String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String hostAddress = null; Integer port = null; IpChannelType ipChannelType = null; Boolean acceptAnonymousConnections = null; Integer maxConcurrentConnectionsCount = null; String[] extraHostAddresses = null; int i = 5; if (args.length > 5) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "host": hostAddress = args[i + 1]; break; case "port": port = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "anonymconnect": acceptAnonymousConnections = Boolean.valueOf(args[i + 1]); break; case "concurrentconnect": maxConcurrentConnectionsCount = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServer(serverName, hostAddress, port, ipChannelType, acceptAnonymousConnections, maxConcurrentConnectionsCount, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeServer(serverName); return String.format(SCTPOAMMessages.REMOVE_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("start")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.startServer(serverName); return String.format(SCTPOAMMessages.START_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("stop")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.stopServer(serverName); return String.format(SCTPOAMMessages.STOP_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showServers(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("association")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 8 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String type = args[4]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { if (args.length < 9) { return M3UAOAMMessages.INVALID_COMMAND; } String peerIp = args[5]; int peerPort = Integer.parseInt(args[6]); String hostIp = args[7]; String[] hostAddresses = hostIp.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[8]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 9; if (args.length > 9) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addAssociation(primaryAddress, hostPort, peerIp, peerPort, assocName, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String serverName = args[5]; String peerIp = args[6]; int peerPort = Integer.parseInt(args[7]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 8; if (args.length > 8) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } if (this.sctpManagement == null) { this.setDefaultValue(); } if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServerAssociation(peerIp, peerPort, serverName, assocName, ipChnnelType); return String.format(SCTPOAMMessages.ADD_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("modify")) { String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String type = args[5]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { String hostAddress = null; Integer hostPort = null; String peerAddress = null; Integer peerPort = null; IpChannelType ipChannelType = null; String[] extraHostAddresses = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "host": hostAddress = args[i + 1]; break; case "port": hostPort = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyAssociation(hostAddress, hostPort, peerAddress, peerPort, assocName, ipChannelType, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String peerAddress = null; Integer peerPort = null; String serverName = null; IpChannelType ipChannelType = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "servername": serverName = args[i + 1]; break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServerAssociation(assocName, peerAddress, peerPort, serverName, ipChannelType); return String.format(SCTPOAMMessages.MODIFY_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeAssociation(assocName); return String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showAssociations(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("set")) { return this.manageSet(args); } else if (args[1].equals("get")) { return this.manageGet(args); } return M3UAOAMMessages.INVALID_COMMAND; } catch (Exception e) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), e); return e.toString(); } catch (Throwable t) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), t); return t.toString(); } } }
SCTPShellExecutor implements ShellExecutor { @Override public String execute(String[] args) { try { if (this.sctpManagements.size() == 0) { return M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN; } if (args.length < 2 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1] == null) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1].equals("server")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 6 || args.length > 10) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String hostAddress = args[4]; if (hostAddress == null) { return M3UAOAMMessages.INVALID_COMMAND; } String[] hostAddresses = hostAddress.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[5]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 6; if (args.length > 6) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServer(serverName, primaryAddress, hostPort, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("modify")) { String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String hostAddress = null; Integer port = null; IpChannelType ipChannelType = null; Boolean acceptAnonymousConnections = null; Integer maxConcurrentConnectionsCount = null; String[] extraHostAddresses = null; int i = 5; if (args.length > 5) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "host": hostAddress = args[i + 1]; break; case "port": port = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "anonymconnect": acceptAnonymousConnections = Boolean.valueOf(args[i + 1]); break; case "concurrentconnect": maxConcurrentConnectionsCount = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServer(serverName, hostAddress, port, ipChannelType, acceptAnonymousConnections, maxConcurrentConnectionsCount, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeServer(serverName); return String.format(SCTPOAMMessages.REMOVE_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("start")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.startServer(serverName); return String.format(SCTPOAMMessages.START_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("stop")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.stopServer(serverName); return String.format(SCTPOAMMessages.STOP_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showServers(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("association")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 8 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String type = args[4]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { if (args.length < 9) { return M3UAOAMMessages.INVALID_COMMAND; } String peerIp = args[5]; int peerPort = Integer.parseInt(args[6]); String hostIp = args[7]; String[] hostAddresses = hostIp.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[8]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 9; if (args.length > 9) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addAssociation(primaryAddress, hostPort, peerIp, peerPort, assocName, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String serverName = args[5]; String peerIp = args[6]; int peerPort = Integer.parseInt(args[7]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 8; if (args.length > 8) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } if (this.sctpManagement == null) { this.setDefaultValue(); } if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServerAssociation(peerIp, peerPort, serverName, assocName, ipChnnelType); return String.format(SCTPOAMMessages.ADD_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("modify")) { String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String type = args[5]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { String hostAddress = null; Integer hostPort = null; String peerAddress = null; Integer peerPort = null; IpChannelType ipChannelType = null; String[] extraHostAddresses = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "host": hostAddress = args[i + 1]; break; case "port": hostPort = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyAssociation(hostAddress, hostPort, peerAddress, peerPort, assocName, ipChannelType, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String peerAddress = null; Integer peerPort = null; String serverName = null; IpChannelType ipChannelType = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "servername": serverName = args[i + 1]; break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServerAssociation(assocName, peerAddress, peerPort, serverName, ipChannelType); return String.format(SCTPOAMMessages.MODIFY_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeAssociation(assocName); return String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showAssociations(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("set")) { return this.manageSet(args); } else if (args[1].equals("get")) { return this.manageGet(args); } return M3UAOAMMessages.INVALID_COMMAND; } catch (Exception e) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), e); return e.toString(); } catch (Throwable t) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), t); return t.toString(); } }  }
SCTPShellExecutor implements ShellExecutor { @Override public String execute(String[] args) { try { if (this.sctpManagements.size() == 0) { return M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN; } if (args.length < 2 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1] == null) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1].equals("server")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 6 || args.length > 10) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String hostAddress = args[4]; if (hostAddress == null) { return M3UAOAMMessages.INVALID_COMMAND; } String[] hostAddresses = hostAddress.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[5]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 6; if (args.length > 6) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServer(serverName, primaryAddress, hostPort, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("modify")) { String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String hostAddress = null; Integer port = null; IpChannelType ipChannelType = null; Boolean acceptAnonymousConnections = null; Integer maxConcurrentConnectionsCount = null; String[] extraHostAddresses = null; int i = 5; if (args.length > 5) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "host": hostAddress = args[i + 1]; break; case "port": port = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "anonymconnect": acceptAnonymousConnections = Boolean.valueOf(args[i + 1]); break; case "concurrentconnect": maxConcurrentConnectionsCount = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServer(serverName, hostAddress, port, ipChannelType, acceptAnonymousConnections, maxConcurrentConnectionsCount, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeServer(serverName); return String.format(SCTPOAMMessages.REMOVE_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("start")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.startServer(serverName); return String.format(SCTPOAMMessages.START_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("stop")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.stopServer(serverName); return String.format(SCTPOAMMessages.STOP_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showServers(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("association")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 8 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String type = args[4]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { if (args.length < 9) { return M3UAOAMMessages.INVALID_COMMAND; } String peerIp = args[5]; int peerPort = Integer.parseInt(args[6]); String hostIp = args[7]; String[] hostAddresses = hostIp.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[8]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 9; if (args.length > 9) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addAssociation(primaryAddress, hostPort, peerIp, peerPort, assocName, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String serverName = args[5]; String peerIp = args[6]; int peerPort = Integer.parseInt(args[7]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 8; if (args.length > 8) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } if (this.sctpManagement == null) { this.setDefaultValue(); } if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServerAssociation(peerIp, peerPort, serverName, assocName, ipChnnelType); return String.format(SCTPOAMMessages.ADD_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("modify")) { String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String type = args[5]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { String hostAddress = null; Integer hostPort = null; String peerAddress = null; Integer peerPort = null; IpChannelType ipChannelType = null; String[] extraHostAddresses = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "host": hostAddress = args[i + 1]; break; case "port": hostPort = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyAssociation(hostAddress, hostPort, peerAddress, peerPort, assocName, ipChannelType, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String peerAddress = null; Integer peerPort = null; String serverName = null; IpChannelType ipChannelType = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "servername": serverName = args[i + 1]; break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServerAssociation(assocName, peerAddress, peerPort, serverName, ipChannelType); return String.format(SCTPOAMMessages.MODIFY_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeAssociation(assocName); return String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showAssociations(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("set")) { return this.manageSet(args); } else if (args[1].equals("get")) { return this.manageGet(args); } return M3UAOAMMessages.INVALID_COMMAND; } catch (Exception e) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), e); return e.toString(); } catch (Throwable t) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), t); return t.toString(); } }  Map<String, Management> getSctpManagements(); void setSctpManagements(Map<String, Management> sctpManagementsTemp); @Override String execute(String[] args); @Override boolean handles(String command); }
SCTPShellExecutor implements ShellExecutor { @Override public String execute(String[] args) { try { if (this.sctpManagements.size() == 0) { return M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN; } if (args.length < 2 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1] == null) { return M3UAOAMMessages.INVALID_COMMAND; } if (args[1].equals("server")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 6 || args.length > 10) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String hostAddress = args[4]; if (hostAddress == null) { return M3UAOAMMessages.INVALID_COMMAND; } String[] hostAddresses = hostAddress.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[5]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 6; if (args.length > 6) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServer(serverName, primaryAddress, hostPort, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("modify")) { String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String hostAddress = null; Integer port = null; IpChannelType ipChannelType = null; Boolean acceptAnonymousConnections = null; Integer maxConcurrentConnectionsCount = null; String[] extraHostAddresses = null; int i = 5; if (args.length > 5) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "host": hostAddress = args[i + 1]; break; case "port": port = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "anonymconnect": acceptAnonymousConnections = Boolean.valueOf(args[i + 1]); break; case "concurrentconnect": maxConcurrentConnectionsCount = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServer(serverName, hostAddress, port, ipChannelType, acceptAnonymousConnections, maxConcurrentConnectionsCount, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeServer(serverName); return String.format(SCTPOAMMessages.REMOVE_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("start")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.startServer(serverName); return String.format(SCTPOAMMessages.START_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("stop")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String serverName = args[3]; if (serverName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.stopServer(serverName); return String.format(SCTPOAMMessages.STOP_SERVER_SUCCESS, serverName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showServers(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("association")) { if (args.length < 3 ){ return M3UAOAMMessages.INVALID_COMMAND; } String command = args[2]; if (command == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("create")) { if (args.length < 8 || args.length > 13) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String type = args[4]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { if (args.length < 9) { return M3UAOAMMessages.INVALID_COMMAND; } String peerIp = args[5]; int peerPort = Integer.parseInt(args[6]); String hostIp = args[7]; String[] hostAddresses = hostIp.split(","); String primaryAddress = hostAddresses[0]; String[] secondaryAddresses = null; if (hostAddresses.length > 1) { secondaryAddresses = new String[(hostAddresses.length - 1)]; for (int i = 0; i < secondaryAddresses.length; i++) { secondaryAddresses[i] = hostAddresses[(i + 1)]; } } int hostPort = Integer.parseInt(args[8]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 9; if (args.length > 9) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } this.setDefaultValue(); if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addAssociation(primaryAddress, hostPort, peerIp, peerPort, assocName, ipChnnelType, secondaryAddresses); return String.format(SCTPOAMMessages.ADD_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String serverName = args[5]; String peerIp = args[6]; int peerPort = Integer.parseInt(args[7]); IpChannelType ipChnnelType = null; String sctpStackName = null; int i = 8; if (args.length > 8) { while (i < args.length) { if (args[i].equals("stackname")) { sctpStackName = args[i + 1]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else if (args[i].equals("sockettype")) { ipChnnelType = IpChannelType.getInstance(args[i + 1]); } i = i + 2; } } if (this.sctpManagement == null) { this.setDefaultValue(); } if (ipChnnelType == null) { ipChnnelType = IpChannelType.SCTP; } this.sctpManagement.addServerAssociation(peerIp, peerPort, serverName, assocName, ipChnnelType); return String.format(SCTPOAMMessages.ADD_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } return M3UAOAMMessages.INVALID_COMMAND; } else if (command.equals("modify")) { String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = args[4]; if (sctpStackName == null) { Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } String type = args[5]; if (type == null) { return M3UAOAMMessages.INVALID_COMMAND; } else if (type.equals("CLIENT")) { String hostAddress = null; Integer hostPort = null; String peerAddress = null; Integer peerPort = null; IpChannelType ipChannelType = null; String[] extraHostAddresses = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "host": hostAddress = args[i + 1]; break; case "port": hostPort = Integer.valueOf(args[i + 1]); break; case "extraaddresses": extraHostAddresses = args[i + 1].split(","); break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyAssociation(hostAddress, hostPort, peerAddress, peerPort, assocName, ipChannelType, extraHostAddresses); return String.format(SCTPOAMMessages.MODIFY_CLIENT_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (type.equals("SERVER")) { String peerAddress = null; Integer peerPort = null; String serverName = null; IpChannelType ipChannelType = null; int i = 6; if (args.length > 6) { while (i < args.length) { String currProp = args[i]; switch (currProp) { case "peerhost": peerAddress = args[i + 1]; break; case "peerport": peerPort = Integer.valueOf(args[i + 1]); break; case "sockettype": ipChannelType = IpChannelType.getInstance(args[i + 1]); break; case "servername": serverName = args[i + 1]; break; default: return M3UAOAMMessages.INVALID_COMMAND; } i = i + 2; } } this.sctpManagement.modifyServerAssociation(assocName, peerAddress, peerPort, serverName, ipChannelType); return String.format(SCTPOAMMessages.MODIFY_SERVER_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } } else if (command.equals("destroy")) { if (args.length < 4) { return M3UAOAMMessages.INVALID_COMMAND; } String assocName = args[3]; if (assocName == null) { return M3UAOAMMessages.INVALID_COMMAND; } String sctpStackName = null; if (args.length > 4) { if (!args[4].equals("stackname")) { return M3UAOAMMessages.INVALID_COMMAND; } sctpStackName = args[5]; Management sctpManagementtmp = this.sctpManagements.get(sctpStackName); if (sctpManagementtmp == null) { return String.format(M3UAOAMMessages.NO_SCTP_MANAGEMENT_BEAN_FOR_NAME, sctpStackName); } this.sctpManagement = sctpManagementtmp; } else { this.setDefaultValue(); } this.sctpManagement.removeAssociation(assocName); return String.format(SCTPOAMMessages.REMOVE_ASSOCIATION_SUCCESS, assocName, this.sctpManagement.getName()); } else if (command.equals("show")) { return this.showAssociations(args); } return M3UAOAMMessages.INVALID_COMMAND; } else if (args[1].equals("set")) { return this.manageSet(args); } else if (args[1].equals("get")) { return this.manageGet(args); } return M3UAOAMMessages.INVALID_COMMAND; } catch (Exception e) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), e); return e.toString(); } catch (Throwable t) { logger.error(String.format("Error while executing comand %s", Arrays.toString(args)), t); return t.toString(); } }  Map<String, Management> getSctpManagements(); void setSctpManagements(Map<String, Management> sctpManagementsTemp); @Override String execute(String[] args); @Override boolean handles(String command);  }