там просто обработка эксепшена
такое ощущение что результат выполнения не получает скрипт и ждет его оочень долго .. когда небыло таймаута просто клиент вис и все .. а с таймаутом и пред версии прерывался ..
скрипт
вот
Код:
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.StringTokenizer;
import bitel.billing.common.module.ipn.IPNContractStatus;
import bitel.billing.server.ipn.GateWorker;
import bitel.billing.server.ipn.UserStatus;
import ru.bitel.bgbilling.modules.ipn.server.bean.command;
//import ru.bitel.bgbilling.modules.ipn.server.bean.command.GateCommandUtil;
import ru.bitel.bgbilling.modules.ipn.server.bean.command.LoopPattern;
import bitel.billing.server.ipn.bean.VlanManager;
import bitel.billing.server.util.DefaultServerSetup;
import bitel.billing.server.util.Utils;
import bitel.billing.server.util.telnet.TelnetSession;
import ru.bitel.bgbilling.common.DefaultSetup;
import bitel.billing.common.IPUtils;
import bitel.billing.server.ipn.bean.GateType;
import bitel.billing.server.ipn.bean.RuleType;
import ru.bitel.bgbilling.modules.ipn.common.bean.AddressRangeManager;
import ru.bitel.common.Preferences;
includeBGBS( "bgbs://ru.bitel.bgbilling.kernel.script.common.bean.ScriptLibrary/gateCommandUtiltt" );
protected void doSync()
{
try
{
log.info( "start of cisco........................................................");
host = gate.getHost();
port = gate.getPort();
DefaultServerSetup gateSetup = new DefaultServerSetup( gate.getConfig(), "\r\n" );
pswdLogin = gateSetup.getStringValue("login");
pswdCfg = gateSetup.getStringValue( "cfg.pswd");
timeout = gateSetup.getIntValue( "timeout", 0 );
result = new StringBuffer();
if( log.isDebugEnabled() )
{
log.debug( gate.getId() + " gate: " + host + ":" + port + " pswdLogin: " + pswdLogin + " pswdCfg: " + pswdCfg );
}
session = new TelnetSession( host, port);
session.setTimeout( timeout );
session.setLoginPromptSequence( ":" );
session.connect();
session.setLoginPromptSequence( ":" );
result.append( session.doCommand( pswdLogin ) );
session.setLoginPromptSequence( ":" );
result.append( session.doCommand( pswdCfg ) );
result.append( session.doCommand( "terminal length 0" ) );
result.append( session.doCommand( "terminal width 0" ) );
session.setLoginPromptSequence( ": " );
result.append( session.doCommand( "enable" ) );
session.setLoginPromptSequence( "#" );
result.append( session.doCommand( pswdCfg ) );
result.append( session.doCommand( "configure terminal" ) );
log.debug( "execute commands" );
doCommands( session, result);
result.append( session.doCommand( "exit" ) );
session.doCommandAsync( "exit" );
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
log.info( result );
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
log.debug( "ok" );
} catch (Exception e)
{
throw new RuntimeException ( e );
}
log.info( "end of cisco........................................................");
}
protected void add()
{
}
private void doCommands( TelnetSession session, StringBuffer result) throws IOException
{
for( UserStatus status : statusList )
{
date = new GregorianCalendar();
VlanManager manager = new VlanManager(status.mid, con);
gateId = gate.getId();
log.info("gateId=" + gateId);
vid = manager.getVlan( gateId, status.contractId );
log.info("vid=" + vid);
//TODO - подумать что сделать справилами на добавление
rules = null;
if (status.status == IPNContractStatus.STATUS_OPEN)
{
rules = getOpenRules( status, vid );
}
else if (status.status == IPNContractStatus.STATUS_REMOVED)
{
rules = getRemoveRules( status, vid );
}
//if closed and etc
else
{
rules = getCloseRules( status, vid);
}
if (vid > 0)
{
for ( String rule : rules )
{
result.append( session.doCommand( rule ) );
}
}
}
}
getOpenRules( status, vid )
{
return getRules( status, "\\[OPEN\\](.*)\\[/OPEN\\]", vid );
}
getCloseRules( status, vid )
{
return getRules( status, "\\[CLOSE\\](.*)\\[/CLOSE\\]", vid );
}
getRemoveRules( UserStatus status, int vid )
{
return getRules( status, "\\[REMOVE\\](.*)\\[/REMOVE\\]", vid );
}
getRules( status, template, vid )
{
// пользовательское правило, без типа - то все оставляем как есть
rule = status.rule.getRuleText();
log.info("rule=" + rule);
//типизированное правило
if( status.ruleType != null )
{
rule = generateRule( rule, status.gateType, status.ruleType, vid);
}
log.info("rule=" + rule);
pattern = Pattern.compile( template, Pattern.DOTALL );
m = pattern.matcher( rule );
if (m.find())
{
rule = m.group( 1 );
}
rule.replaceAll( "\r", "" );
parts = rule.split( "\n" );
result = new ArrayList();
for ( String part : parts )
{
if ( !Utils.isEmptyString( part ))
{
result.add( part );
}
}
return result;
}
generateRule( addresses, gateType, ruleType, int vid )
{
ruleText = getRule( gateType, ruleType );
replacements = new HashMap ();
if ( vid > 0)
{
replacements.put( "\\{VID\\}", String.valueOf( vid ) );
}
return generateRule( ruleText, addresses, replacements, ruleType);
}