forum.bitel.ru http://forum.bitel.ru/ |
|
BGInetAccess - NullPointerException (CRM) http://forum.bitel.ru/viewtopic.php?f=44&t=9688 |
Страница 1 из 1 |
Автор: | Виктор [ 11 сен 2014, 13:54 ] |
Заголовок сообщения: | BGInetAccess - NullPointerException |
Добрый день, после вчерашнего обновления появились ошибки в логах: connection 09-11/11:48:40 ERROR [sa-p-13-t-183] EventWorker - class ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorDeviceWorker: java.lang.NullPointerException ru.bitel.bgbilling.common.BGException: java.lang.NullPointerException at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorSet.connect(ServiceActivatorSet.java:204) at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorDeviceWorker.runWorker(ServiceActivatorDeviceWorker.java:223) at ru.bitel.bgbilling.kernel.event.EventWorker.internalRunWorker(EventWorker.java:139) at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorDeviceWorker.runImpl(ServiceActivatorDeviceWorker.java:145) at ru.bitel.common.worker.WorkerTask.run(WorkerTask.java:86) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) at ru.bitel.common.worker.WorkerThread.run(WorkerThread.java:46) Caused by: java.lang.NullPointerException at ru.bitel.bgbilling.modules.inet.dyn.device.manad.FreeBSDServiceActivator.executeCommands(FreeBSDServiceActivator.java:96) at ru.bitel.bgbilling.modules.inet.dyn.device.terminal.AbstractTerminalServiceActivator.connect(AbstractTerminalServiceActivator.java:718) at ru.bitel.bgbilling.modules.inet.dyn.device.manad.FreeBSDServiceActivator.connect(FreeBSDServiceActivator.java:67) at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorSet.connect(ServiceActivatorSet.java:197) ... 12 more connection 09-11/11:48:40 ERROR [sa-p-13-t-84] ServiceActivatorSet - Device:2 - null java.lang.NullPointerException at ru.bitel.bgbilling.modules.inet.dyn.device.manad.FreeBSDServiceActivator.executeCommands(FreeBSDServiceActivator.java:96) at ru.bitel.bgbilling.modules.inet.dyn.device.terminal.AbstractTerminalServiceActivator.disconnect(AbstractTerminalServiceActivator.java:726) at ru.bitel.bgbilling.modules.inet.dyn.device.manad.FreeBSDServiceActivator.disconnect(FreeBSDServiceActivator.java:74) at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorSet.disconnect(ServiceActivatorSet.java:226) at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorDeviceWorker.runWorker(ServiceActivatorDeviceWorker.java:252) at ru.bitel.bgbilling.kernel.event.EventWorker.internalRunWorker(EventWorker.java:139) at ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorDeviceWorker.runImpl(ServiceActivatorDeviceWorker.java:145) at ru.bitel.common.worker.WorkerTask.run(WorkerTask.java:86) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:304) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) at ru.bitel.common.worker.WorkerThread.run(WorkerThread.java:46) скрипт FreeBSDServiceActivator немного измененный ManadServiceActivator Код: package ru.bitel.bgbilling.modules.inet.dyn.device.manad;
import java.io.PrintWriter; import java.net.InetSocketAddress; import java.net.Socket; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.log4j.Logger; import ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivator; import ru.bitel.bgbilling.modules.inet.access.sa.ServiceActivatorEvent; import ru.bitel.bgbilling.modules.inet.api.common.bean.InetConnection; import ru.bitel.bgbilling.modules.inet.api.common.bean.InetDevice; import ru.bitel.bgbilling.modules.inet.api.common.bean.InetDeviceType; import ru.bitel.bgbilling.modules.inet.api.common.bean.InetServ; import ru.bitel.bgbilling.modules.inet.dyn.device.terminal.AbstractTerminalServiceActivator; import ru.bitel.bgbilling.server.util.Setup; import ru.bitel.common.ParameterMap; import ru.bitel.common.Utils; public class FreeBSDServiceActivator extends AbstractTerminalServiceActivator implements ServiceActivator { private static Logger logger = Logger.getLogger( ManadServiceActivator.class ); private Set<Integer> ipResourceIds; private InetDevice inetDevice; protected static final Pattern paramMultiPattern = Pattern.compile( "\\$paramMulti\\((.*)\\)" ); private Socket socket; PrintWriter out; @Override public Object init( Setup setup, int moduleId, InetDevice device, InetDeviceType deviceType, ParameterMap config ) throws Exception { super.init( setup, moduleId, device, deviceType, config ); this.inetDevice = device; this.ipResourceIds = Utils.toIntegerSet( config.get( "sa.ipResourceIds", null ) ); List<InetSocketAddress> hosts = device.getHosts(); return null; } @Override public Object connect() throws Exception { List<InetSocketAddress> hosts = inetDevice.getHosts(); InetSocketAddress socketAddress = hosts.get( 0 ); String host = socketAddress.getAddress().getHostAddress(); int port = socketAddress.getPort(); socket = new Socket( host, port ); out = new PrintWriter( socket.getOutputStream(), true ); logger.info( "Connected" ); return super.connect(); } @Override public Object disconnect() throws Exception { super.disconnect(); out.close(); socket.close(); logger.info( "Disconnected" ); return null; } @Override protected void executeCommand( String command ) throws Exception { logger.info( "execute: " + command ); out.println( command ); } @Override protected Object executeCommands( ServiceActivatorEvent e, InetServ serv, InetConnection connection, Set<Integer> options, String[] commands ) throws Exception { InetServ inetServ = e.getNewInetServ()!=null? e.getNewInetServ() : e.getOldInetServ(); if ( this.ipResourceIds.size()>0 && !this.ipResourceIds.contains( inetServ.getIpResourceId() ) ) { return null; } if( commands == null ) { return null; } if( this.workingOptions != null ) { options = new HashSet<Integer>( options ); options.retainAll( this.workingOptions ); } List<InetServ> childrens = serv.getChildren(); List<InetServ> servs = new ArrayList<>(); //если потомков у сервиса нет, то мы только его обрабатываем String fullCommand = generateRule( commands, serv, servs, e, connection, options ); fullCommand = fullCommand.replaceAll( "\\\\t", "\t" ); fullCommand = fullCommand.replaceAll( "\n", "|" ); logger.debug( "fullCommand=" + fullCommand ); if( Utils.notBlankString( fullCommand ) ) { executeCommand( fullCommand.trim() ); } return null; } public final String generateRule( String[] commands, InetServ mainServ, List<InetServ> servs, ServiceActivatorEvent e, InetConnection connection, Set<Integer> options ) { String commandStr = ""; for( String command : commands ) { commandStr += command + "\n"; } //Если указан макрос multiParam, учитываем его commandStr = getParamMulti( commandStr ); StringBuffer resultBuf = null; resultBuf = new StringBuffer (); String loopPattern = "(<LOOP>.*?</LOOP>)?(.*?)<LOOP>(.*?)</LOOP>"; Pattern pattern = Pattern.compile( loopPattern, Pattern.DOTALL ); Matcher m = pattern.matcher( commandStr ); boolean find = false; while( m.find() ) { find = true; String block = m.group( 3 ).trim(); block = processBlock( block, servs, e, connection, options ).toString(); String beforeLoop = m.group( 2 ); beforeLoop = this.macrosFormat.format( beforeLoop, e, mainServ, connection, options ); resultBuf.append( beforeLoop.trim() + "\n" ); resultBuf.append( block.trim() ); } if (find) { //хвост(ищем жадным алгоритмом) или если вообще нет ни одного цикла loopPattern = "(?:<LOOP>(?:.*)</LOOP>)(.*)\\z"; pattern = Pattern.compile( loopPattern, Pattern.DOTALL ); m = pattern.matcher( commandStr ); if( m.find() ) { String afterLoop = m.group( 1 ).trim(); afterLoop = this.macrosFormat.format( afterLoop, e, mainServ, connection, options ); resultBuf.append( afterLoop.trim() ); } } else { commandStr = this.macrosFormat.format( commandStr, e, mainServ, connection, options ); resultBuf.append( commandStr ); } return resultBuf.toString(); } private String getParamMulti( String commands ) { Matcher matcher = paramMultiPattern.matcher( commands ); if( matcher.find() ) { String prefix = matcher.group( 1 ); String param = this.config.get( prefix, "" ); // команды заведены отдельными параметрами if( Utils.isBlankString( param ) ) { param = ""; for( ParameterMap params : this.config.subIndexed( prefix + "." ).values() ) { String command = params.get( "", null ); if( Utils.notBlankString( command ) ) { param += command + "\n"; } } } return param; } return commands; } private StringBuffer processBlock( String ruleText, List<InetServ> servs, ServiceActivatorEvent e, InetConnection connection, Set<Integer> options ) { StringBuffer result = new StringBuffer(); List<PatternItem> items = new ArrayList<PatternItem>( 10 ); Map<String, Integer> letterMaxNumbers = new HashMap<String, Integer>(); Pattern pattern = Pattern.compile( "\\{([A-Z]+)(\\d+)\\}" ); Matcher m = pattern.matcher( ruleText ); while( m.find() ) { String letter = m.group( 1 ); int number = Utils.parseInt( m.group( 2 ), 0 ); PatternItem item = new PatternItem(); item.number = number; item.letter = letter; items.add( item ); Integer maxNumber = letterMaxNumbers.get( letter ); if( maxNumber == null || maxNumber < number ) { letterMaxNumbers.put( letter, number ); } } final int size = servs.size(); for( int i = 0; i < size; i++ ) { //String address = IPUtils.convertLongIpToString( Utils.parseLong( addreses[i], 0 ) ); String addressRule = new String( ruleText ); InetServ serv = servs.get( i ); for( PatternItem item : items ) { int number = i*(letterMaxNumbers.get( item.letter ) + 1) + item.number; addressRule = addressRule.replaceAll( "\\{" + item.letter + item.number + "\\}", "{" + item.letter + number + "}" ); } String str = addressRule; str = this.macrosFormat.format( str, e, serv, connection, options ); result.append( str + "\n" ); } return result; } private static class PatternItem { public String letter; public int number; } } |
Автор: | Amir [ 11 сен 2014, 14:07 ] |
Заголовок сообщения: | Re: BGInetAccess - NullPointerException |
Попробуйте пока добавить после Код: @Override и перед protected Object executeCommands( ServiceActivatorEvent e, InetServ serv, InetConnection connection, Set<Integer> options, String[] commands ) throws Exception { Код: InetServ inetServ = e.getNewInetServ()!=null? e.getNewInetServ() : e.getOldInetServ(); Код: if( e == null ) , скомпилировать и перечитать конфигурацию на серверах.
{ return super.executeCommands( e, serv, connection, options, commands ); } |
Автор: | Виктор [ 11 сен 2014, 14:26 ] |
Заголовок сообщения: | Re: BGInetAccess - NullPointerException |
Спасибо, помогло |
Автор: | stark [ 11 сен 2014, 18:52 ] |
Заголовок сообщения: | Re: BGInetAccess - NullPointerException |
Исправили ManadServiceAcivator, будет в следующем обновлении. |
Страница 1 из 1 | Часовой пояс: UTC + 5 часов [ Летнее время ] |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |