perfsonar-dev - perfsonar: r3320 - in branches/geant2_java-sshtelnet-mp-STABLE: ant conf conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters doc doc/commands doc/schema samples src/main/java/org/perfsonar/service/measurementPoint src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters src/main/java/org/perfso nar/service/measurementPoint/lookingGlassType/ip/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6 src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands src/main/java/org/perfsonar/service/measurementPoint/remote/common src/main/java/org/perfsonar/service/measurementPoint/remote/ssh src/main/java/org/perfsonar/service/measurementPoint/remote/telnet src/main/java/org/perfsonar/service/measurementPoint/webAdmin
Subject: perfsonar development work
List archive
perfsonar: r3320 - in branches/geant2_java-sshtelnet-mp-STABLE: ant conf conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters doc doc/commands doc/schema samples src/main/java/org/perfsonar/service/measurementPoint src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters src/main/java/org/perfso nar/service/measurementPoint/lookingGlassType/ip/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6 src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands src/main/java/org/perfsonar/service/measurementPoint/remote/common src/main/java/org/perfsonar/service/measurementPoint/remote/ssh src/main/java/org/perfsonar/service/measurementPoint/remote/telnet src/main/java/org/perfsonar/service/measurementPoint/webAdmin
Chronological Thread
- From:
- To:
- Subject: perfsonar: r3320 - in branches/geant2_java-sshtelnet-mp-STABLE: ant conf conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters doc doc/commands doc/schema samples src/main/java/org/perfsonar/service/measurementPoint src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters src/main/java/org/perfso nar/service/measurementPoint/lookingGlassType/ip/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6 src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands src/main/java/org/perfsonar/service/measurementPoint/remote/common src/main/java/org/perfsonar/service/measurementPoint/remote/ssh src/main/java/org/perfsonar/service/measurementPoint/remote/telnet src/main/java/org/perfsonar/service/measurementPoint/webAdmin
- Date: Wed, 6 Feb 2008 10:41:36 -0500
Author: melis
Date: 2008-02-06 10:41:34 -0500 (Wed, 06 Feb 2008)
New Revision: 3320
Added:
branches/geant2_java-sshtelnet-mp-STABLE/conf/servlet.properties
branches/geant2_java-sshtelnet-mp-STABLE/conf/servlet.properties.template
branches/geant2_java-sshtelnet-mp-STABLE/doc/Functionality Specification
for SSHTelnet 1.3.doc
branches/geant2_java-sshtelnet-mp-STABLE/doc/Interface Specification for
SSHTelnet 1.3.doc
branches/geant2_java-sshtelnet-mp-STABLE/doc/Metadata Configuration file
for SSHTelnet 1.3.doc
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/commands-complete-list-v5-SM.xls
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/commands_minimum_set-v5-SM.xls
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/MetadataKeyRequest.rnc
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/MetadataKeyResponse.rnc
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/SetupDataRequest.rnc
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/SetupDataResponse.rnc
branches/geant2_java-sshtelnet-mp-STABLE/samples/sshtelnetmptemplate.csv
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/DbMetadataConfiguration.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/MetadataConfiguration.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/MyUserInfo.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/webAdmin/
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/webAdmin/SSHTelnetHandler.java
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/ant/axis-deploy-targets.xml
branches/geant2_java-sshtelnet-mp-STABLE/ant/configure-targets.xml
branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties
branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties.template
branches/geant2_java-sshtelnet-mp-STABLE/ant/libs-download-targets.xml
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscobgpcommands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipcommands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipv6commands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscominimumpackage.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscostatuscommands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties
branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties.template
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperbgpcommands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipcommands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipv6commands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperminimumpackage.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperstatuscommands.txt
branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties
branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties.template
branches/geant2_java-sshtelnet-mp-STABLE/conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.class
branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties
branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties.template
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
Log:
updated STABLE branch with 1.3RC1
Modified: branches/geant2_java-sshtelnet-mp-STABLE/ant/axis-deploy-targets.xml
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/ant/axis-deploy-targets.xml
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/ant/axis-deploy-targets.xml
2008-02-06 15:41:34 UTC (rev 3320)
@@ -50,12 +50,12 @@
depends="copy-dep-base-service-jars">
<copy
file="${basedir}/lib/repository/nmwg/nmwg/1.0.20071008/nmwg-1.0.20071008.jar"
todir="${service.home}/${deploy.root}/WEB-INF/lib"/>
- <copy
file="${basedir}/lib/repository/perfsonar/perfsonar-base/1.0.20071107/perfsonar-base-1.0.20071107.jar"
todir="${service.home}/${deploy.root}/WEB-INF/lib"/>
+ <copy
file="${basedir}/lib/repository/perfsonar/perfsonar-base/1.0.20080115/perfsonar-base-1.0.20080115.jar"
todir="${service.home}/${deploy.root}/WEB-INF/lib"/>
<copy file="${basedir}/conf/eventType-map.xml"
todir="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf"/>
<copy file="${basedir}/conf/eventType-rules.xml"
todir="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf"/>
+ <copy file="${basedir}/conf/metadata.xml"
todir="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf"/>
-
<copy file="${basedir}/conf/wsdd/${wsdd.file.deploy}"
todir="${service.home}/${deploy.root}/wsdd"/>
<copy file="${basedir}/conf/wsdd/${wsdd.file.undeploy}"
todir="${service.home}/${deploy.root}/wsdd"/>
Modified: branches/geant2_java-sshtelnet-mp-STABLE/ant/configure-targets.xml
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/ant/configure-targets.xml
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/ant/configure-targets.xml
2008-02-06 15:41:34 UTC (rev 3320)
@@ -70,25 +70,40 @@
<fileset
dir="./lib/repository/wss4j/wss4j/1.5.1">
<include name="*.jar"/>
</fileset>
+ <fileset
dir="./lib/repository/jdom/jdom/1.0b8">
+ <include name="*.jar"/>
+ </fileset>
</classpath>
- <arg value="../conf/service.properties"/>
+ <arg value="../conf/metadata.xml"/>
</java>
<propertyfile file="${basedir}/conf/service.properties">
- <entry key="service.sax_parser.config"
value="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf/objects.config"/>
- <entry key="service.log.log4j.config"
value="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf/log4j.properties"/>
+ <entry key="service.sax_parser.config"
value="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf/objects.config"/>
+ <entry key="service.log.log4j.config"
value="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf/log4j.properties"/>
+ <entry key="service.ls.registration_file"
value="${service.home}/${deploy.root}/WEB-INF/classes/perfsonar/conf/metadata.xml"/>
+
<!-- for LookupInfoRequest message -->
<entry key="service.r.service_type" value="mp"/>
+ <entry key="service.r.type" value="mp"/>
<entry key="service.r.service_name"
value="${service.name}"/>
<entry key="service.r.service_version"
value="${version}"/>
+ <entry key="service.mp.message_types"
value="SetupDataRequest,MetadataKeyRequest,EchoRequest"/>
+
<entry key="service.as.authn_active"
value="on"/>
<entry key="service.as.authn_for_msg_types"
value="SetupDataRequest,MetadataKeyRequest"/>
<entry key="service.as.point"
value="http://homer.rediris.es:8080/perfSONAR-AS/services/AuthService"/>
<entry key="service.mp.class_name"
value="org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.WebserviceEngineAdapter"/>
+
+ <entry key="component.mp.xmldb.db_uri"
value="xmldb:exist://localhost:8680/exist/xmlrpc/db"/>
+ <entry key="component.mp.xmldb.db_uri.xmlrpc"
value="xmldb:exist://localhost:8680/exist/xmlrpc/db"/>
+ <entry key="component.mp.xmldb.db_username"
value="sshtelnet"/>
+ <entry key="component.mp.xmldb.db_password"
value="sshtelnet"/>
+ <entry key="component.mp.xmldb.db_access"
value="xmlrpc"/>
+ <entry key="component.mp.xmldb.metadata_file_name"
value="metadata.xml"/>
</propertyfile>
</target>
Modified: branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties
2008-02-06 15:41:34 UTC (rev 3320)
@@ -8,10 +8,10 @@
target.server=127.0.0.1
-service.name=JAVA-SSHTELNET-MP
+service.name=geant2_java-sshtelnet-mp
jarfilename=perfsonar-sshtelnet-mp
-version=1.2.1
+version=1.3RC1
exist.war.file=exist-1.0.1.war
exist.war.download.url=http://www.perfsonar.net/download/dependencies/preinstall_download.php?product=exist-war&version=1.0.1
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties.template
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties.template
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/ant/const.properties.template
2008-02-06 15:41:34 UTC (rev 3320)
@@ -8,10 +8,10 @@
target.server=127.0.0.1
-service.name=JAVA-SSHTELNET-MP
+service.name=geant2_java-sshtelnet-mp
jarfilename=perfsonar-sshtelnet-mp
-version=1.2.1
+version=1.3RC1
exist.war.file=exist-1.0.1.war
exist.war.download.url=http://www.perfsonar.net/download/dependencies/preinstall_download.php?product=exist-war&version=1.0.1
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/ant/libs-download-targets.xml
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/ant/libs-download-targets.xml
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/ant/libs-download-targets.xml
2008-02-06 15:41:34 UTC (rev 3320)
@@ -59,10 +59,11 @@
<artifact:dependencies>
- <dependency groupId="rrdjtool" artifactId="rrdjtool"
version="1.0"/>
- <dependency groupId="perfsonar" artifactId="perfsonar-base"
version="1.0.20071107"/>
- <dependency groupId="nmwg" artifactId="nmwg"
version="1.0.20071008"/>
+ <dependency groupId="rrdjtool" artifactId="rrdjtool"
version="1.0"/>
+ <dependency groupId="perfsonar" artifactId="perfsonar-base"
version="1.0.20080115"/>
+ <dependency groupId="nmwg" artifactId="nmwg"
version="1.0.20071008"/>
+
<localRepository refid="local.repository"/>
<remoteRepository refid="remote.repository"/>
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscobgpcommands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscobgpcommands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscobgpcommands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,7 +1,6 @@
-BGP_ROUTE_IPv4@@@show ip bgp@@@1@@@1@@@cache@@@show bgp routing table@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-BGP_SUMMARY@@@show ip bgp summary@@@0@@@0@@@cache@@@show status of all BGP
connections@@@---@@@---
-BGP_DAMPENED_PATHS@@@show ip bgp dampening
dampened-paths@@@0@@@0@@@cache@@@show all dampened BGP paths@@@---@@@---
-BGP_NEIGHBOUR_ADVERTISED@@@show ip bgp neighbour@@@2@@@2@@@cache@@@show
advertised prefixes from <ip address>@@@<ip address>
advertised-routes@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
advertised-routes$
-BGP_NEIGHBOUR_RECEIVED@@@show ip bgp neighbour@@@2@@@2@@@cache@@@show
received prefixes from <ip address>@@@<ip address>
received-routes@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
received-routes$
-BGP_DAMPENING_FLAP-STATISTICS@@@show ip bgp dampening
flap-statistics@@@0@@@0@@@cache@@@display information about all currently
flapping BGP routes@@@---@@@---
-BGP_MULTICAST_TABLE_IPv4@@@show ip bgp ipv4
multicast@@@1@@@1@@@cache@@@display ipv4 multicast table@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
\ No newline at end of file
+IP_BGP_ROUTE@@@show ip bgp@@@1@@@1@@@cache@@@show bgp routing
table@@@<prefix> [<length>]@@@.*
+IP_BGP_SUMMARY@@@show ip bgp summary@@@0@@@0@@@cache@@@show status of all
BGP connections@@@---@@@---
+IP_BGP_DAMPENED_PATHS@@@show ip bgp dampening
dampened-paths@@@0@@@0@@@cache@@@show all dampened BGP paths@@@---@@@---
+IP_BGP_NEIGHBOUR_ADVERTISED@@@show ip bgp neighbor@@@1@@@1@@@cache@@@show
advertised prefixes from <ip address>@@@<ip address>
advertised-routes@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
advertised-routes$
+IP_BGP_NEIGHBOUR_RECEIVED@@@show ip bgp neighbor@@@1@@@1@@@cache@@@show
receivede prefixes from <ip address>@@@<ip address>
received-routes@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
received-routes$
+IP_BGP_DAMPENING_FLAP_STATISTICS@@@show ip bgp dampening
flap-statistics@@@0@@@0@@@cache@@@display information about all currently
flapping BGP routes@@@---@@@---
\ No newline at end of file
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipcommands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipcommands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipcommands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,21 +1,27 @@
+IP_INTERFACE_ADDRESS@@@show ip interface brief@@@0@@@0@@@cache@@@display
interface addresses@@@---@@@---
+IP_PROTOCOLS@@@show ip protocols@@@0@@@0@@@cache@@@display detailed
information about IP protocols currently configured on the router@@@---@@@---
IP_ACCESS_LIST@@@show ip access-lists@@@0@@@0@@@cache@@@display ip access
lists@@@---@@@---
-IP_INTERFACE@@@show ip interface@@@1@@@1@@@cache@@@display information about
interfaces running IP@@@<interface>@@@---
+IP_INTERFACE@@@show ip interface@@@1@@@1@@@cache@@@display information about
interfaces running IP@@@<interface>@@@.*
+IP_PING@@@ping@@@1@@@1@@@cache@@@ping an <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_TRACEROUTE@@@trace@@@1@@@1@@@cache@@@trace the IP path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_OSPF_DB@@@show ip ospf database@@@0@@@0@@@cache@@@display the OSPF
database@@@---@@@---
+IP_OSPF_NEIGHBOR@@@show ip ospf neighbor@@@0@@@0@@@cache@@@display the OSPF
neighbour list@@@---@@@---
+IP_OSPF_DB_EXT@@@show ospf database external@@@1@@@1@@@cache@@@display the
OSPF database externa link states@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_ROUTE@@@show ip route@@@1@@@1@@@cache@@@show the current IP routing table
for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_BGP_TABLE@@@show ip bgp IP multicast@@@1@@@1@@@cache@@@display
IP multicast table@@@<prefix> [<length>]@@@.*
IP_MULTICAST_ROUTE@@@show ip mroute@@@1@@@1@@@cache@@@display multicast
forwarding state@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_MULTICAST_SDP_SA-CACHE@@@show ip msdp sa-cache@@@1@@@1@@@cache@@@display
(S,G) state learned from MSDP peers@@@<as number>@@@[0-9]*
+IP_MULTICAST_SDP_SA-CACHE@@@show ip msdp sa-cache@@@1@@@1@@@cache@@@display
(S,G) state learned from MSDP peers@@@<peer IP
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
IP_MULTICAST_SDP_SUM@@@show ip msdp sum@@@0@@@0@@@cache@@@display MSDP peer
status@@@---@@@---
IP_MULTICAST_SDP_COUNT@@@show ip msdp count@@@0@@@0@@@cache@@@display MSDP
counters@@@---@@@---
IP_MULTICAST_SDP_PEER@@@show ip msdp peer@@@1@@@1@@@cache@@@display detailed
information about an MSDP peer@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_OSPF_DB@@@show ip ospf database external@@@1@@@1@@@cache@@@display the
OSPF database external LSA for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_PROTOCOLS@@@show ip protocols@@@0@@@0@@@cache@@@display detailed
information about IP protocols currently configured on the router@@@---@@@---
-IP_SHOW_ROUTE@@@show ip route@@@1@@@1@@@cache@@@show the current IP routing
table for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_RPF@@@show ip rpf@@@0@@@0@@@cache@@@display RPF information for <ip
address>@@@---@@@---
-IP_SAP@@@show ip sap@@@0@@@0@@@cache@@@display the SAP cache@@@---@@@---
-IP_SAP_DETAIL@@@show ip sap detail@@@0@@@0@@@cache@@@display the SAP cache
details@@@---@@@---
-IP_PING@@@ping@@@1@@@1@@@cache@@@ping an <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_TRACEROUTE@@@trace@@@1@@@1@@@cache@@@trace the IPv4 path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_MULTICAST_TRACEROUTE@@@mtrace@@@1@@@1@@@cache@@@trace the path of a
packet from the specified source interface to the receivers of the multicast
traffics@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_SHOW_VRF@@@show ip vrf@@@0@@@0@@@cache@@@display VPN Routing/Forwarding
instance information@@@---@@@---
-IP_SHOW_VRF_DETAIL@@@show ip vrf detail@@@0@@@0@@@cache@@@display detailled
VPN Routing/Forwarding instance information@@@---@@@---
-IP_SHOW_ROUTE_VRF@@@show ip route vrf@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<VPN name>@@@---
-IP_PING_VRF@@@ping vrf@@@1@@@1@@@cache@@@pings an <ip address> that has a
specific VRF@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_TRACEROUTE_VRF@@@trace vrf@@@1@@@1@@@cache@@@displays the path to <ip
address> that has a specific VRF@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
\ No newline at end of file
+IP_MULTICAST_RPF@@@show ip rpf@@@1@@@1@@@cache@@@display RPF information for
<ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_SAP@@@show ip sap@@@0@@@0@@@cache@@@display the SAP
cache@@@---@@@---
+IP_MULTICAST_SAP_DETAIL@@@show ip sap detail@@@0@@@0@@@cache@@@display the
SAP cache details@@@---@@@---
+IP_MULTICAST_TRACEROUTE@@@mtrace@@@1@@@1@@@cache@@@trace the path of a
packet from the specified source interface to the receivers of the multicast
traffic@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MPLS_L2_VC@@@show IP_MPLS l2transport vc@@@0@@@0@@@cache@@@display
information about Any Transport over IP_MPLS (AToM) virtual circuits
(VCs)@@@---@@@---
+IP_MPLS_L2_VC_DETAIL@@@show IP_MPLS l2transport vc
detail@@@0@@@0@@@cache@@@display detailed information about Any Transport
over IP_MPLS (AToM) virtual circuits (VCs)@@@---@@@---
+IP_MPS_FORWARDING-TABLE@@@show IP_MPLS
forwarding-table@@@1@@@1@@@cache@@@display IP_MPLS forwarding
table@@@<interface>@@@.*
+IP_MPLS_VRF_LIST@@@show ip vrf brief@@@0@@@0@@@cache@@@list the Virtual
Private Network (VPN) routing/forwarding instance (VRF)@@@---@@@---
+IP_MPLS_VRF_ROUTE@@@show ip route vrf@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<routing-instance name>@@@.*
+IP_MPLS_VRF_PING@@@ping vrf@@@1@@@1@@@cache@@@pings an <ip address> that has
a specific VRF@@@<VPN name> <ip address>@@@^.*
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MPLS_VRF_TRACEROUTE@@@trace vrf@@@1@@@1@@@cache@@@displays the path to
<ip address> that has a specific VRF@@@<VPN name> <ip address>@@@^.*
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
\ No newline at end of file
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipv6commands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipv6commands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscoipv6commands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,8 +1,19 @@
-IPv6_SHOW_ROUTE@@@show ipv6 route@@@1@@@1@@@cache@@@display IPv6 routing
table entry for <ipv6 address>@@@<ipv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_INTERFACE@@@show ipv6 interface@@@1@@@1@@@cache@@@display the
interfaces which are configured for IPv6@@@<interface>@@@---
-IPv6_SHOW_ACCESS_LIST@@@show ipv6 access-list@@@0@@@0@@@cache@@@display IPv6
access lists@@@---@@@---
-IPv6_BGP_TABLE@@@show bgp ipv6@@@1@@@1@@@cache@@@display current BGP table
routing entry for <IPv6 prefix>@@@<IPv6 prefix network/length>@@@---
-IPv6_BGP_SUMMARY@@@show bgp ipv6 summary@@@0@@@0@@@cache@@@display the
status of all current IPv6 BGP connections@@@---@@@---
-IPv6_BGP_FLAP-STATISTICS@@@show bgp ipv6
flap-statistics@@@0@@@0@@@cache@@@display IPv6 BGP flap statistics@@@---@@@---
-IPv6_PING@@@ping ipv6@@@1@@@1@@@cache@@@ping an <ipv6 address>@@@<ipv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_TRACEROUTE@@@trace ipv6@@@1@@@1@@@cache@@@trace the ipv6 path to <ipv6
address>@@@<ipv6 address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
\ No newline at end of file
+IPv6_INTERFACE_ADDRESS@@@show IPv6 interface brief@@@0@@@0@@@cache@@@display
interface IPv6 addresses@@@---@@@---
+IPv6_PROTOCOLS@@@show IPv6 protocols@@@0@@@0@@@cache@@@display detailed
information about IPv6 protocols currently configured on the
router@@@---@@@---
+IPv6_ACCESS_LIST@@@show IPv6 access-lists@@@0@@@0@@@cache@@@display IPv6
access lists@@@---@@@---
+IPv6_BGP_TABLE@@@show bgp IPv6 unicast@@@1@@@1@@@cache@@@display current BGP
table routing entry for <IPv6 prefix>@@@<IPv6 prefix network> [<length>]@@@.*
+IPv6_BGP_SUMMARY@@@show bgp ipv6 unicast@@@0@@@0@@@cache@@@display the
status of all current IPv6 BGP connections@@@---@@@---
+IPv6_BGP_DAMPENED_PATHS@@@show bgp IPv6
dampened-paths@@@0@@@0@@@cache@@@show all dampened BGP paths@@@---@@@---
+IPv6_BGP_NEIGHBOUR_ADVERTISED@@@show bgp IPv6 unicast
neighors@@@1@@@1@@@cache@@@show advertised prefixes from <IPv6
address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?
advertised-routes$
+IPv6_BGP_NEIGHBOUR_RECEIVED@@@show bgp IPv6 unicast
neighbors@@@1@@@1@@@cache@@@show received prefixes from <IPv6
address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})? received
routes$
+IPv6_BGP_DAMPENING_FLAP_STATISTICS@@@show bgp IPv6 unicast dampening
flap-statistics@@@0@@@0@@@cache@@@display information about all flapping BGP
routes@@@---@@@---
+IPv6_INTERFACE@@@show IPv6 interface@@@1@@@1@@@cache@@@display information
about interfaces running IPv6@@@<interface>@@@.*
+IPv6_PING@@@ping IPv6@@@1@@@1@@@cache@@@Ping an <IPv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_TRACEROUTE@@@trace@@@1@@@1@@@cache@@@trace the IPv6 path to <IPv6
address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_OSPF_DB@@@show IPv6 ospf database@@@0@@@0@@@cache@@@display the OSPF3
neighbour list@@@---@@@---
+IPv6_OSPF_NEIGHBOR@@@show IPv6 ospf neighbor@@@0@@@0@@@cache@@@display the
OSPF3 database@@@---@@@---
+IPv6_OSPF_DB_EXT@@@show IPv6 ospf database
external@@@0@@@0@@@cache@@@display the OSPF3 database external link
status@@@---@@@---
+IPv6_ROUTE@@@show IPv6 route@@@1@@@1@@@cache@@@display IPv6 routing table
entry for <IPv6 address>@@@[<IPv6
address>]@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_MULTICAST_BGP_TABLE@@@show bgp IPv6 multicast@@@1@@@1@@@cache@@@display
IPv6 multicast table@@@<IPv6 prefix/prefix-length>@@@.*
+IPv6_MULTICAST_ROUTE@@@show IPv6 mroute@@@1@@@1@@@cache@@@display multicast
IPv6 forwarding state@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_MULTICAST_RPF@@@show IPv6 rpf@@@1@@@1@@@cache@@@display RPF information
for <IPv6 address>@@@<IPv6-prefix>@@@.*
\ No newline at end of file
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscominimumpackage.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscominimumpackage.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscominimumpackage.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,15 +1,28 @@
-STATUS_SHOW_ENVIRONMENT@@@show environment@@@0@@@0@@@cache@@@show chassis
environment@@@---@@@---
-STATUS_INTERFACE_STATS@@@show interface@@@1@@@1@@@cache@@@show interface
statistics@@@<interface>@@@---
-BGP_ROUTE_IPv4@@@show ip bgp@@@1@@@1@@@cache@@@show bgp routing table@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_SHOW_ROUTE@@@show ip route@@@1@@@1@@@cache@@@show the current IP routing
table for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-STATUS_SHOW_INTERFACE_CONFIGURATION@@@show running
interface@@@1@@@1@@@cache@@@display the interface configuration for
<interface>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+STATUS_HW_ENVIRONMENT@@@show environment@@@0@@@0@@@cache@@@show device
environmental variables@@@---@@@---
+STATUS_INTERFACE_STATS@@@show interface@@@0@@@1@@@cache@@@show interface
statistics@@@[<interface>]@@@.*
+STATUS_INTERFACE_DESCRIPTION@@@show interface
description@@@0@@@0@@@cache@@@show interface descriptions@@@---@@@---
+IP_INTERFACE_ADDRESS@@@show ip interface brief@@@0@@@0@@@cache@@@display
interface addresses@@@---@@@---
+IP_BGP_ROUTE@@@show ip bgp@@@1@@@1@@@cache@@@show bgp routing
table@@@<prefix> [<length>]@@@.*
+IP_BGP_SUMMARY@@@show ip bgp summary@@@0@@@0@@@cache@@@show status of all
BGP connections@@@---@@@---
+IP_BGP_NEIGHBOUR_ADVERTISED@@@show ip bgp neighbor@@@1@@@1@@@cache@@@show
advertised prefixes from <ip address>@@@<ip address>
advertised-routes@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
advertised-routes$
+IP_BGP_NEIGHBOUR_RECEIVED@@@show ip bgp neighbor@@@1@@@1@@@cache@@@show
receivede prefixes from <ip address>@@@<ip address>
received-routes@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
received-routes$
IP_PING@@@ping@@@1@@@1@@@cache@@@ping an <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_TRACEROUTE@@@trace@@@1@@@1@@@cache@@@trace the IPv4 path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IPv6_SHOW_ROUTE@@@show ipv6 route@@@1@@@1@@@cache@@@display IPv6 routing
table entry for <ipv6 address>@@@<ipv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_BGP_TABLE@@@show bgp ipv6@@@1@@@1@@@cache@@@display current BGP table
routing entry for <IPv6 prefix>@@@<IPv6 prefix network/length>@@@---
-IPv6_PING@@@ping ipv6@@@1@@@1@@@cache@@@ping an <ipv6 address>@@@<ipv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_TRACEROUTE@@@trace ipv6@@@1@@@1@@@cache@@@trace the ipv6 path to <ipv6
address>@@@<ipv6 address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-STATUS_SHOW_MPLS_L2_VC_DETAIL@@@show mpls l2transport vc
detail@@@0@@@0@@@cache@@@display detailed information about Any Transport
over MPLS (AToM) virtual circuits (VCs)@@@---@@@---
-IP_SHOW_ROUTE_VRF@@@show ip route vrf@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<VPN name>@@@---
-IP_PING_VRF@@@ping vrf@@@1@@@1@@@cache@@@pings an <ip address> that has a
specific VRF@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_TRACEROUTE_VRF@@@trace vrf@@@1@@@1@@@cache@@@displays the path to <ip
address> that has a specific VRF@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
\ No newline at end of file
+IP_TRACEROUTE@@@trace@@@1@@@1@@@cache@@@trace the IP path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_ROUTE@@@show ip route@@@1@@@1@@@cache@@@show the current IP routing table
for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_BGP_TABLE@@@show ip bgp IP multicast@@@1@@@1@@@cache@@@display
IP multicast table@@@<prefix> [<length>]@@@.*
+IP_MULTICAST_ROUTE@@@show ip mroute@@@1@@@1@@@cache@@@display multicast
forwarding state@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_SDP_SUM@@@show ip msdp sum@@@0@@@0@@@cache@@@display MSDP peer
status@@@---@@@---
+IP_MULTICAST_TRACEROUTE@@@mtrace@@@1@@@1@@@cache@@@trace the path of a
packet from the specified source interface to the receivers of the multicast
traffic@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IPv6_INTERFACE_ADDRESS@@@show IPv6 interface brief@@@0@@@0@@@cache@@@display
interface IPv6 addresses@@@---@@@---
+IPv6_BGP_TABLE@@@show bgp IPv6 unicast@@@1@@@1@@@cache@@@display current BGP
table routing entry for <IPv6 prefix>@@@<IPv6 prefix network> [<length>]@@@.*
+IPv6_BGP_SUMMARY@@@show bgp ipv6 unicast@@@0@@@0@@@cache@@@display the
status of all current IPv6 BGP connections@@@---@@@---
+IPv6_BGP_NEIGHBOUR_ADVERTISED@@@show bgp IPv6 unicast
neighors@@@1@@@1@@@cache@@@show advertised prefixes from <IPv6
address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?
advertised-routes$
+IPv6_BGP_NEIGHBOUR_RECEIVED@@@show bgp IPv6 unicast
neighbors@@@1@@@1@@@cache@@@show received prefixes from <IPv6
address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})? received
routes$
+IPv6_PING@@@ping IPv6@@@1@@@1@@@cache@@@Ping an <IPv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_TRACEROUTE@@@trace@@@1@@@1@@@cache@@@trace the IPv6 path to <IPv6
address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_ROUTE@@@show IPv6 route@@@1@@@1@@@cache@@@display IPv6 routing table
entry for <IPv6 address>@@@[<IPv6
address>]@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_MULTICAST_ROUTE@@@show IPv6 mroute@@@1@@@1@@@cache@@@display multicast
IPv6 forwarding state@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IP_MPLS_VRF_LIST@@@show ip vrf brief@@@0@@@0@@@cache@@@list the Virtual
Private Network (VPN) routing/forwarding instance (VRF)@@@---@@@---
+IP_MPLS_VRF_ROUTE@@@show ip route vrf@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<routing-instance name>@@@.*
+IP_MPLS_VRF_PING@@@ping vrf@@@1@@@1@@@cache@@@pings an <ip address> that has
a specific VRF@@@<VPN name> <ip address>@@@^.*
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MPLS_VRF_TRACEROUTE@@@trace vrf@@@1@@@1@@@cache@@@displays the path to
<ip address> that has a specific VRF@@@<VPN name> <ip address>@@@^.*
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
\ No newline at end of file
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscostatuscommands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscostatuscommands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/ciscostatuscommands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,9 +1,5 @@
-STATUS_SHOW_ENVIRONMENT@@@show environment@@@0@@@0@@@cache@@@show chassis
environment@@@---@@@---
-STATUS_INTERFACE_STATS@@@show interface@@@1@@@1@@@cache@@@show interface
statistics@@@<interface>@@@---
-STATUS_INTERFACE_DESCRIPTION@@@show interface
description@@@0@@@0@@@cache@@@show interface descriptions@@@---@@@---
-STATUS_SHOW_MODULE@@@show module@@@0@@@0@@@cache@@@display hardware module
status and information@@@---@@@---
-STATUS_SHOW_INTERFACE_CONFIGURATION@@@show running
interface@@@1@@@1@@@cache@@@display the interface configuration for
<interface>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-STATUS_SOFTWARE_VERSION@@@show version@@@0@@@0@@@cache@@@show the current
router software version@@@---@@@---
-STATUS_SHOW_MPLS_L2_VC@@@show mpls l2transport vc@@@0@@@0@@@cache@@@display
information about Any Transport over MPLS (AToM) virtual circuits
(VCs)@@@---@@@---
-STATUS_SHOW_MPLS_L2_VC_DETAIL@@@show mpls l2transport vc
detail@@@0@@@0@@@cache@@@display detailed information about Any Transport
over MPLS (AToM) virtual circuits (VCs)@@@---@@@---
-STATUS_SHOW_MPLS_FORWARDING-TABLE@@@show mpls
forwarding-table@@@1@@@1@@@cache@@@display MPLS forwarding
table@@@<interface>@@@---
\ No newline at end of file
+STATUS_HW_ENVIRONMENT@@@show environment@@@0@@@0@@@cache@@@show device
environmental variables@@@---@@@---
+STATUS_SW_VERSION@@@show version@@@0@@@0@@@cache@@@show the current router
software version@@@---@@@---
+STATUS_INTERFACE_STATS@@@show interface@@@0@@@1@@@cache@@@show interface
statistics@@@[<interface>]@@@.*
+STATUS_INTERFACE_CONF@@@show running interface@@@0@@@1@@@cache@@@display the
interface configuration for <interface>@@@[<interface>]@@@.*
+STATUS_INTERFACE_DESCRIPTION@@@show interface
description@@@0@@@0@@@cache@@@show interface descriptions@@@---@@@---
\ No newline at end of file
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,20 +1,24 @@
# File contains components to load
# Config and logger MUST be load as first!
-
-#Configuration component - must be the first one!
+#Group=PropertiesConfiguration
+#Description=Configuration component - must be the first one!
config=org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent
-#Logger component - must be the second one!
+#Group=Logging
+#Description=Logger component - must be the second one!
logger=org.perfsonar.base.auxiliary.components.logger.log4j.Log4jLoggerComponent
-# Simple scheduler
+#Group=Scheduler
+#Description=Simple scheduler
#scheduler=org.perfsonar.base.auxiliary.components.simplescheduler.Scheduler
-# Registration in LS
+#Group=LS
+#Description=Registration in LS
#registrator=org.perfsonar.service.measurementArchive.register.LSRegistrationComponent
-# Authentication
+#Group=AuthN
+#Description=Authentication component
authn=org.perfsonar.base.auxiliary.components.authn.wssec.WSSecAuthNComponent
#Service specific components
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties.template
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties.template
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/conf/components.properties.template
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,20 +1,24 @@
# File contains components to load
# Config and logger MUST be load as first!
-
-#Configuration component - must be the first one!
+#Group=PropertiesConfiguration
+#Description=Configuration component - must be the first one!
config=org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent
-#Logger component - must be the second one!
+#Group=Logging
+#Description=Logger component - must be the second one!
logger=org.perfsonar.base.auxiliary.components.logger.log4j.Log4jLoggerComponent
-# Simple scheduler
+#Group=Scheduler
+#Description=Simple scheduler
#scheduler=org.perfsonar.base.auxiliary.components.simplescheduler.Scheduler
-# Registration in LS
+#Group=LS
+#Description=Registration in LS
#registrator=org.perfsonar.service.measurementArchive.register.LSRegistrationComponent
-# Authentication
+#Group=AuthN
+#Description=Authentication component
authn=org.perfsonar.base.auxiliary.components.authn.wssec.WSSecAuthNComponent
#Service specific components
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperbgpcommands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperbgpcommands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperbgpcommands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
-BGP_ROUTE_IPv4@@@show route protocol bgp@@@1@@@1@@@cache@@@show bgp routing
table@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-BGP_SUMMARY@@@show bgp summary@@@0@@@0@@@cache@@@show status of all BGP
connections@@@---@@@---
-BGP_DAMPENED_PATHS@@@show route protocol bgp damping decayed
detail@@@0@@@0@@@cache@@@show all dampened BGP paths@@@---@@@---
-BGP_NEIGHBOUR_ADVERTISED@@@show route advertising-protocol
bgp@@@1@@@1@@@cache@@@show advertised prefixes from <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-BGP_NEIGHBOUR_RECEIVED@@@show route receive-protocol
bgp@@@1@@@1@@@cache@@@show received prefixes from <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-BGP_MULTICAST_TABLE_IPv4@@@show route protocol bgp table
inet.2@@@1@@@1@@@cache@@@display ipv4 multicast table@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
\ No newline at end of file
+IP_BGP_ROUTE@@@show route protocol bgp@@@1@@@1@@@cache@@@show bgp routing
table@@@<prefix> [<length>]@@@.*
+IP_BGP_SUMMARY@@@show bgp summary@@@0@@@0@@@cache@@@show status of all BGP
connections@@@---@@@---
+IP_BGP_DAMPENED_PATHS@@@show route protocol bgp damping suppressed
detail@@@0@@@0@@@cache@@@show all dampened BGP paths@@@---@@@---
+IP_BGP_NEIGHBOUR_ADVERTISED@@@show route advertising-protocol
bgp@@@1@@@1@@@cache@@@show advertised prefixes from <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_BGP_NEIGHBOUR_RECEIVED@@@show route receive-protocol
bgp@@@1@@@1@@@cache@@@show receivede prefixes from <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_BGP_DAMPENING_FLAP_STATISTICS@@@show route protocol bgp damping history
detail@@@0@@@0@@@cache@@@display information about all currently flapping BGP
routes@@@---@@@---
\ No newline at end of file
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipcommands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipcommands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipcommands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,19 +1,26 @@
+IP_INTERFACE_ADDRESS@@@show interfaces terse@@@0@@@0@@@cache@@@display
interface addresses@@@---@@@---
IP_ACCESS_LIST@@@show interfaces filters@@@0@@@0@@@cache@@@display ip access
lists@@@---@@@---
+IP_INTERFACE@@@show interfaces@@@1@@@1@@@cache@@@display information about
interfaces running IP@@@<interface> extensive@@@^.+ extensive$
+IP_PING@@@ping count 5 rapid@@@1@@@1@@@cache@@@ping an <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@trace the IP path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_OSPF_DB@@@show ospf database@@@0@@@0@@@cache@@@display the OSPF
database@@@---@@@---
+IP_OSPF_NEIGHBOR@@@show ospf neighbor@@@0@@@0@@@cache@@@display the OSPF
neighbour list@@@---@@@---
+IP_OSPF_DB_EXT@@@show ospf database extern@@@0@@@0@@@cache@@@display the
OSPF database externa link states@@@---@@@---
+IP_ROUTE@@@show route@@@1@@@1@@@cache@@@show the current IP routing table
for <ip address>@@@<prefix> [<length>]@@@.*
+IP_MULTICAST_BGP_TABLE@@@show route protocol bgp table
inet.2@@@1@@@1@@@cache@@@display IP multicast table@@@<prefix> [<length>]@@@.*
IP_MULTICAST_ROUTE@@@show multicast route@@@1@@@1@@@cache@@@display
multicast forwarding state@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_MULTICAST_SDP_SA-CACHE@@@show msdp source-active
peer@@@1@@@1@@@cache@@@display (S,G) state learned from MSDP peers@@@<peer ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_SDP_SA-CACHE@@@show msdp source-active
peer@@@1@@@1@@@cache@@@display (S,G) state learned from MSDP peers@@@<peer IP
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
IP_MULTICAST_SDP_SUM@@@show msdp@@@0@@@0@@@cache@@@display MSDP peer
status@@@---@@@---
IP_MULTICAST_SDP_COUNT@@@show msdp statistics@@@0@@@0@@@cache@@@display MSDP
counters@@@---@@@---
-IP_MULTICAST_SDP_PEER@@@show msdp peer@@@2@@@2@@@cache@@@display detailed
information about an MSDP peer@@@<ip address>
detail@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
detail$
-IP_OSPF_DB@@@show ospf database extern@@@1@@@1@@@cache@@@display the OSPF
database external LSA for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_SHOW_ROUTE@@@show route@@@1@@@1@@@cache@@@show the current IP routing
table for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_RPF@@@show multicast rpf@@@1@@@1@@@cache@@@display RPF information for
<ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_SAP@@@show multicast sessions@@@0@@@0@@@cache@@@display the SAP
cache@@@---@@@---
-IP_SAP_DETAIL@@@show multicast sessions detail@@@0@@@0@@@cache@@@displays
the SAP cache details@@@---@@@---
-IP_PING@@@ping rapid count 5@@@4@@@4@@@cache@@@ping an <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@trace the IPv4 path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_TRACEROUTE_MULTICAST@@@mtrace@@@1@@@1@@@cache@@@trace the path of a
packet from the specified source interface to the receivers of the multicast
traffic@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_SHOW_VRF@@@show configuration routing-instance@@@1@@@1@@@cache@@@display
VPN Routing/Forwarding instance information@@@<routing-instance name>@@@---
-IP_SHOW_VRF_DETAIL@@@show configuration
routing-instance@@@1@@@1@@@cache@@@display detailed VPN Routing/Forwarding
instance information@@@<routing-instance name>@@@---
-IP_SHOW_ROUTE_VRF@@@show route table@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<routing-instance name>@@@---
-IP_PING_VRF@@@ping@@@3@@@3@@@cache@@@pings an <ip address> that has a
specific VRF@@@<ip address> routing-instance <routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .*$
-IP_TRACEROUTE_VRF@@@traceroute@@@3@@@3@@@cache@@@displays the path to <ip
address> that has a specific VRF@@@<ip address> routing-instance
<routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .*$
\ No newline at end of file
+IP_MULTICAST_SDP_PEER@@@show msdp peer@@@1@@@1@@@cache@@@display detailed
information about an MSDP peer@@@<ip address>
detail@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
detail$
+IP_MULTICAST_RPF@@@show multicast rpf@@@1@@@1@@@cache@@@display RPF
information for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_SAP@@@show multicast sessions@@@0@@@0@@@cache@@@display the SAP
cache@@@---@@@---
+IP_MULTICAST_SAP_DETAIL@@@show multicast sessions
detail@@@0@@@0@@@cache@@@display the SAP cache details@@@---@@@---
+IP_MULTICAST_TRACEROUTE@@@mtrace@@@1@@@1@@@cache@@@trace the path of a
packet from the specified source interface to the receivers of the multicast
traffic@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MPLS_L2_VC@@@show l2circuit connections@@@0@@@0@@@cache@@@display
information about Any Transport over IP_MPLS (AToM) virtual circuits
(VCs)@@@---@@@---
+IP_MPLS_L2_VC_DETAIL@@@show l2circuit connections
extensive@@@0@@@0@@@cache@@@display detailed information about Any Transport
over IP_MPLS (AToM) virtual circuits (VCs)@@@---@@@---
+IP_MPS_FORWARDING-TABLE@@@show route forwarding-table family
IP_MPLS@@@0@@@0@@@cache@@@display IP_MPLS forwarding table@@@---@@@---
+IP_MPLS_VRF_LIST@@@show route instance brief@@@0@@@0@@@cache@@@list the
Virtual Private Network (VPN) routing/forwarding instance (VRF)@@@---@@@---
+IP_MPLS_VRF_ROUTE@@@show route table@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<routing-instance name>@@@.*
+IP_MPLS_VRF_PING@@@ping@@@1@@@1@@@cache@@@pings an <ip address> that has a
specific VRF@@@<ip address> routing-instance <routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .+$
+IP_MPLS_VRF_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@displays the path to
<ip address> that has a specific VRF@@@<ip address> routing-instance
<routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .+$
\ No newline at end of file
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipv6commands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipv6commands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperipv6commands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,7 +1,18 @@
-IPv6_SHOW_ROUTE@@@show route table inet6@@@1@@@1@@@cache@@@display IPv6
routing table entry for <ipv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_INTERFACES@@@show interfaces@@@2@@@2@@@cache@@@display the interfaces
which are configured for IPv6@@@<interface> extensive@@@.* extensive$
-IPv6_SHOW_ACCESS_LIST@@@show interfaces filters@@@0@@@0@@@cache@@@display
IPv6 access lists@@@---@@@---
-IPv6_BGP_TABLE@@@show route protocol bgp table
inet6@@@1@@@1@@@cache@@@description@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
+IPv6_INTERFACE_ADDRESS@@@show interfaces terse@@@0@@@0@@@cache@@@display
interface IPv6 addresses@@@---@@@---
+IPv6_ACCESS_LIST@@@show interfaces filters@@@0@@@0@@@cache@@@display IPv6
access lists@@@---@@@---
+IPv6_BGP_TABLE@@@show route protocol bgp table
inet6@@@1@@@1@@@cache@@@display current BGP table routing entry for <IPv6
prefix>@@@<IPv6 prefix
network/length>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
IPv6_BGP_SUMMARY@@@show bgp summary@@@0@@@0@@@cache@@@display the status of
all current IPv6 BGP connections@@@---@@@---
-IPv6_PING@@@ping inet6@@@1@@@1@@@cache@@@ping an <ipv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_TRACEROUTE@@@traceroute inet6@@@1@@@1@@@cache@@@trace the ipv6 path to
<ipv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
\ No newline at end of file
+IPv6_BGP_DAMPENED_PATHS@@@show route protocol bgp table inet6.0 damping
suppressed@@@0@@@0@@@cache@@@show all dampened BGP paths@@@---@@@---
+IPv6_BGP_NEIGHBOUR_ADVERTISED@@@show route table inet6.0
advertising-protocol bgp@@@1@@@1@@@cache@@@show advertised prefixes from
<IPv6 address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_BGP_NEIGHBOUR_RECEIVED@@@show route table inet6.0 receive-protocol
bgp@@@1@@@1@@@cache@@@show received prefixes from <IPv6 address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_BGP_DAMPENING_FLAP_STATISTICS@@@show route protocol bgp table inet6.0
damping history@@@0@@@0@@@cache@@@display information about all flapping BGP
routes@@@---@@@---
+IPv6_INTERFACE@@@show interfaces@@@1@@@1@@@cache@@@display information about
interfaces running IPv6@@@<interface> extensive@@@^.+ extensive$
+IPv6_PING@@@ping count 5 rapid@@@1@@@1@@@cache@@@Ping an <IPv6
address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@trace the IPv6 path to <IPv6
address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_OSPF_DB@@@show ospf3 database@@@0@@@0@@@cache@@@display the OSPF3
neighbour list@@@---@@@---
+IPv6_OSPF_NEIGHBOR@@@show ospf3 neighbor@@@0@@@0@@@cache@@@display the OSPF3
database@@@---@@@---
+IPv6_OSPF_DB_EXT@@@show ospf3 database extern@@@0@@@0@@@cache@@@display the
OSPF3 database external link status@@@---@@@---
+IPv6_ROUTE@@@show route table inet6@@@0@@@1@@@cache@@@display IPv6 routing
table entry for <IPv6 address>@@@[<IPv6
address>]@@@^(([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?)?$
+IPv6_MULTICAST_BGP_TABLE@@@show route protocol bgp table
inet6.2@@@1@@@1@@@cache@@@display IPv6 multicast table@@@<IPv6 prefix>
[<prefix-length>]@@@.*
+IPv6_MULTICAST_ROUTE@@@show multicast route inet6@@@1@@@1@@@cache@@@display
multicast IPv6 forwarding state@@@<IPv6-prefix/prefix-length>@@@.*
+IPv6_MULTICAST_RPF@@@show multicast rpf inet6@@@1@@@1@@@cache@@@display RPF
information for <IPv6 address>@@@<IPv6 address> [<prefix-length>]@@@.*
\ No newline at end of file
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperminimumpackage.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperminimumpackage.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperminimumpackage.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,15 +1,29 @@
-STATUS_INTERFACE_STATS@@@show interfaces@@@1@@@1@@@cache@@@show interface
statistics@@@<interface>@@@---
+STATUS_HW_ENVIRONMENT@@@show chassis environment@@@0@@@0@@@cache@@@show
device environmental variables@@@---@@@---
+STATUS_INTERFACE_STATS@@@show interfaces@@@0@@@1@@@cache@@@show interface
statistics@@@[<interface>]@@@.*
STATUS_INTERFACE_DESCRIPTION@@@show interfaces
descriptions@@@0@@@0@@@cache@@@show interfaces descriptions@@@---@@@---
-BGP_ROUTE_IPv4@@@show route protocol bgp@@@1@@@1@@@cache@@@show bgp routing
table@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IP_SHOW_ROUTE@@@show route@@@1@@@1@@@cache@@@show the current IP routing
table for <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-STATUS_SHOW_INTERFACE_CONFIGURATION@@@show configuration
interfaces@@@1@@@1@@@cache@@@display the interface configuration for
<interface>@@@<interface>@@@---
-IP_PING@@@ping@@@4@@@4@@@cache@@@ping an <ip address>@@@<ip address> count 5
rapid@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})? count
5 rapid$
-IP_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@trace the IPv4 path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
-IPv6_SHOW_ROUTE@@@show route table inet6@@@1@@@1@@@cache@@@display IPv6
routing table entry for <ipv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_BGP_TABLE@@@show route protocol bgp table
inet6@@@1@@@1@@@cache@@@description@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_PING@@@ping inet6@@@1@@@1@@@cache@@@ping an <ipv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-IPv6_TRACEROUTE@@@traceroute inet6@@@1@@@1@@@cache@@@trace the ipv6 path to
<ipv6 address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9](\/[0-9]{1,3})?$
-STATUS_MPLS_L2_VC_DETAIL@@@show l2circuit connections
extensive@@@0@@@0@@@cache@@@display detailled information about Any Transport
over MPLS (AToM) virtual circuits
(VCs)@@@---@---
-IP_SHOW_ROUTE_VRF@@@show route table@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<routing-instance name>@@@---
-IP_PING_VRF@@@ping@@@3@@@3@@@cache@@@pings an <ip address> that has a
specific VRF@@@<ip address> routing-instance <routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .*$
-IP_TRACEROUTE_VRF@@@traceroute@@@3@@@3@@@cache@@@displays the path to <ip
address> that has a specific VRF@@@<ip address> routing-instance
<routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .*$
\ No newline at end of file
+IP_INTERFACE_ADDRESS@@@show interfaces terse@@@0@@@0@@@cache@@@display
interface addresses@@@---@@@---
+IP_BGP_ROUTE@@@show route protocol bgp@@@1@@@1@@@cache@@@show bgp routing
table@@@<prefix> [<length>]@@@.*
+IP_BGP_SUMMARY@@@show bgp summary@@@0@@@0@@@cache@@@show status of all BGP
connections@@@---@@@---
+IP_BGP_NEIGHBOUR_ADVERTISED@@@show route advertising-protocol
bgp@@@1@@@1@@@cache@@@show advertised prefixes from <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_BGP_NEIGHBOUR_RECEIVED@@@show route receive-protocol
bgp@@@1@@@1@@@cache@@@show receivede prefixes from <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_PING@@@ping count 5 rapid@@@1@@@1@@@cache@@@ping an <ip address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@trace the IP path to <ip
address>@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_ROUTE@@@show route@@@1@@@1@@@cache@@@show the current IP routing table
for <ip address>@@@<prefix> [<length>]@@@.*
+IP_MULTICAST_BGP_TABLE@@@show route protocol bgp table
inet.2@@@1@@@1@@@cache@@@display IP multicast table@@@<prefix> [<length>]@@@.*
+IP_MULTICAST_ROUTE@@@show multicast route@@@1@@@1@@@cache@@@display
multicast forwarding state@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MULTICAST_SDP_SUM@@@show msdp@@@0@@@0@@@cache@@@display MSDP peer
status@@@---@@@---
+IP_MULTICAST_TRACEROUTE@@@mtrace@@@1@@@1@@@cache@@@trace the path of a
packet from the specified source interface to the receivers of the multicast
traffic@@@<ip
address>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IPv6_INTERFACE_ADDRESS@@@show interfaces terse@@@0@@@0@@@cache@@@display
interface IPv6 addresses@@@---@@@---
+IPv6_BGP_TABLE@@@show route protocol bgp table
inet6@@@1@@@1@@@cache@@@display current BGP table routing entry for <IPv6
prefix>@@@<IPv6 prefix
network/length>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_BGP_SUMMARY@@@show bgp summary@@@0@@@0@@@cache@@@display the status of
all current IPv6 BGP connections@@@---@@@---
+IPv6_BGP_NEIGHBOUR_ADVERTISED@@@show route table inet6.0
advertising-protocol bgp@@@1@@@1@@@cache@@@show advertised prefixes from
<IPv6 address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_BGP_NEIGHBOUR_RECIEVED@@@show route table inet6.0 receive-protocol
bgp@@@1@@@1@@@cache@@@show received prefixes from <IPv6 address>@@@<peer IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_PING@@@ping count 5 rapid@@@1@@@1@@@cache@@@Ping an <IPv6
address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@trace the IPv6 path to <IPv6
address>@@@<IPv6
address>@@@^([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?$
+IPv6_ROUTE@@@show route table inet6@@@0@@@1@@@cache@@@display IPv6 routing
table entry for <IPv6 address>@@@[<IPv6
address>]@@@^(([A-Fa-f0-9]{1,4}:){7}[A-Fa-f0-9]{1,4}(/[0-9]{1,3})?)?$
+IPv6_MULTICAST_BGP_TABLE@@@show route protocol bgp table
inet6.2@@@1@@@1@@@cache@@@display IPv6 multicast table@@@<IPv6 prefix>
[<prefix-length>]@@@.*
+IPv6_MULTICAST_ROUTE@@@show multicast route inet6@@@1@@@1@@@cache@@@display
multicast IPv6 forwarding state@@@<IPv6-prefix/prefix-length>@@@.*
+IP_MPLS_VRF_LIST@@@show route instance brief@@@0@@@0@@@cache@@@list the
Virtual Private Network (VPN) routing/forwarding instance (VRF)@@@---@@@---
+IP_MPLS_VRF_ROUTE@@@show route table@@@1@@@1@@@cache@@@display the IP
routing table associated with a Virtual Private Network (VPN)
routing/forwarding instance (VRF)@@@<routing-instance name>@@@.*
+IP_MPLS_VRF_PING@@@ping count 5 rapid
routing-instance@@@1@@@1@@@cache@@@pings an <ip address> that has a specific
VRF@@@<routing-instance name> <ip address>@@@^.+
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?$
+IP_MPLS_VRF_TRACEROUTE@@@traceroute@@@1@@@1@@@cache@@@displays the path to
<ip address> that has a specific VRF@@@<ip address> routing-instance
<routing-instance
name>@@@^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\/[0-9]{1,2})?
routing-instance .+$
\ No newline at end of file
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperstatuscommands.txt
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperstatuscommands.txt
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/juniperstatuscommands.txt
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,9 +1,5 @@
-STATUS_SHOW_ENVIRONMENT@@@show chassis environment@@@0@@@0@@@cache@@@show
chassis
environment@@@---@---
-STATUS_INTERFACE_STATS@@@show interfaces@@@1@@@1@@@cache@@@show interface
statistics@@@<interface>@@@---
-STATUS_INTERFACE_DESCRIPTIOM@@@show interfaces
descriptions@@@0@@@0@@@cache@@@show interfaces descriptions@@@---@@@---
-STATUS_SHOW_INTERFACE_CONFIGURATION@@@show configuration
interfaces@@@1@@@1@@@cache@@@display the interface configuration for
<interface>@@@<interface>@@@---
-STATUS_SOFTWARE_VERSION@@@show version@@@0@@@0@@@cache@@@show the current
router software version@@@---@@@---
-STATUS_SHOW_UPTIME@@@show system uptime@@@0@@@0@@@cache@@@show the system's
current uptime@@@---@@@---
-STATUS_MPLS_L2_VC@@@show l2circuit connections@@@0@@@0@@@cache@@@display
information about Any Transport over MPLS (AToM) virtual circuits
(VCs)@@@---@---
-STATUS_MPLS_L2_VC_DETAIL@@@show l2circuit connections
extensive@@@0@@@0@@@cache@@@display detailled information about Any Transport
over MPLS (AToM) virtual circuits
(VCs)@@@---@---
-STATUS_MPLS_FORWARDING-TABLE@@@show route forwarding-table family
mpls@@@0@@@0@@@cache@@@display MPLS forwarding table@@@---@@@---
\ No newline at end of file
+STATUS_HW_ENVIRONMENT@@@show chassis environment@@@0@@@0@@@cache@@@show
device environmental
variables@@@---@---
+STATUS_SW_VERSION@@@show version@@@0@@@0@@@cache@@@show the current router
software version@@@---@@@---
+STATUS_INTERFACE_STATS@@@show interfaces@@@0@@@1@@@cache@@@show interface
statistics@@@[<interface>]@@@.*
+STATUS_SHOW_INTERFACE_CONF@@@show configuration
interfaces@@@0@@@1@@@cache@@@display the interface configuration for
<interface>@@@[<interface>]@@@.*
+STATUS_INTERFACE_DESCRIPTIOM@@@show interfaces
descriptions@@@0@@@0@@@cache@@@show interfaces descriptions@@@---@@@---
\ No newline at end of file
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties
2008-02-06 15:41:34 UTC (rev 3320)
@@ -3,60 +3,145 @@
## project : perfSONAR
## author: romradz
+#Group=Logger
+#Description=location of the log directory
+logDir=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs
-logDir=${service.home}/${deploy.root}/WEB-INF/logs
-
#ROOT
+#Group=RootLogger
+#Description=The maximum backup index for the root logger
#log4j.appender.rootAppender.MaxBackupIndex=11
-#log4j.appender.rootAppender.File=${service.home}/${deploy.root}/WEB-INF/logs/perfsonar.log
+#Group=RootLogger
+#Description=The file for the root logger
+#log4j.appender.rootAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar.log
+#Group=RootLogger
+#Description=The class responsible for the layout of the root logger
#log4j.appender.rootAppender.layout=org.apache.log4j.PatternLayout
+#Group=RootLogger
+#Description=The conversion pattern for the root logger
#log4j.appender.rootAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=RootLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
#log4j.rootLogger=DEBUG, rootAppender
+#Group=RootLogger
+#Description=The maximum file size for the root logger
#log4j.appender.rootAppender.MaxFileSize=500KB
+#Group=RootLogger
+#Description=The class responsible for appending text in the root logger
#log4j.appender.rootAppender=org.apache.log4j.RollingFileAppender
#DEBUG
+#Group=DebugLogger
+#Description=The maximum backup index for the debug logger
log4j.appender.debugAppender.MaxBackupIndex=11
-log4j.appender.debugAppender.File=${service.home}/${deploy.root}/WEB-INF/logs/perfsonar_debug.log
+#Group=DebugLogger
+#Description=The file for the debug logger
+log4j.appender.debugAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_debug.log
+#Group=DebugLogger
+#Description=The class responsible for the layout of the debug logger
log4j.appender.debugAppender.layout=org.apache.log4j.PatternLayout
+#Group=DebugLogger
+#Description=The conversion pattern for the debug logger
log4j.appender.debugAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=DebugLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-debug=DEBUG, debugAppender
+#Group=DebugLogger
+#Description=The maximum file size for the debug logger
log4j.appender.debugAppender.MaxFileSize=500KB
+#Group=DebugLogger
+#Description=The class responsible for appending text in the debug logger
log4j.appender.debugAppender=org.apache.log4j.RollingFileAppender
#INFO
+#Group=InfoLogger
+#Description=The maximum backup index for the info logger
log4j.appender.infoAppender.MaxBackupIndex=11
-log4j.appender.infoAppender.File=${service.home}/${deploy.root}/WEB-INF/logs/perfsonar_info.log
+#Group=InfoLogger
+#Description=The file for the info logger
+log4j.appender.infoAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_info.log
+#Group=InfoLogger
+#Description=The class responsible for the layout of the info logger
log4j.appender.infoAppender.layout=org.apache.log4j.PatternLayout
+#Group=InfoLogger
+#Description=The conversion pattern for the info logger
log4j.appender.infoAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=InfoLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-info=INFO, infoAppender
+#Group=InfoLogger
+#Description=The maximum file size for the info logger
log4j.appender.infoAppender.MaxFileSize=500KB
+#Group=InfoLogger
+#Description=The class responsible for appending text in the info logger
log4j.appender.infoAppender=org.apache.log4j.RollingFileAppender
#WARN
+#Group=WarnLogger
+#Description=The maximum backup index for the warning logger
log4j.appender.warnAppender.MaxBackupIndex=11
-log4j.appender.warnAppender.File=${service.home}/${deploy.root}/WEB-INF/logs/perfsonar_warn.log
+#Group=WarnLogger
+#Description=The file for the warning logger
+log4j.appender.warnAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_warn.log
+#Group=WarnLogger
+#Description=The class responsible for the layout of the warning logger
log4j.appender.warnAppender.layout=org.apache.log4j.PatternLayout
+#Group=WarnLogger
+#Description=The conversion pattern for the warning logger
log4j.appender.warnAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=WarnLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-warn=WARN, warnAppender
+#Group=WarnLogger
+#Description=The maximum file size for the warning logger
log4j.appender.warnAppender.MaxFileSize=500KB
+#Group=WarnLogger
+#Description=The class responsible for appending text in the warning logger
log4j.appender.warnAppender=org.apache.log4j.RollingFileAppender
#ERROR
+#Group=ErrorLogger
+#Description=The maximum backup index for the error logger
log4j.appender.errorAppender.MaxBackupIndex=11
-log4j.appender.errorAppender.File=${service.home}/${deploy.root}/WEB-INF/logs/perfsonar_error.log
+#Group=ErrorLogger
+#Description=The file for the error logger
+log4j.appender.errorAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_error.log
+#Group=ErrorLogger
+#Description=The class responsible for the layout of the error logger
log4j.appender.errorAppender.layout=org.apache.log4j.PatternLayout
+#Group=ErrorLogger
+#Description=The conversion pattern for the error logger
log4j.appender.errorAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=ErrorLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-error=ERROR, errorAppender
+#Group=ErrorLogger
+#Description=The maximum file size for the error logger
log4j.appender.errorAppender.MaxFileSize=500KB
+#Group=ErrorLogger
+#Description=The class responsible for appending text in the error logger
log4j.appender.errorAppender=org.apache.log4j.RollingFileAppender
#FATAL
+#Group=FatalLogger
+#Description=The maximum backup index for the fatal logger
log4j.appender.fatalAppender.MaxBackupIndex=11
-log4j.appender.fatalAppender.File=${service.home}/${deploy.root}/WEB-INF/logs/perfsonar_fatal.log
+#Group=FatalLogger
+#Description=The file for the fatal logger
+log4j.appender.fatalAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_fatal.log
+#Group=FatalLogger
+#Description=The class responsible for the layout of the fatal logger
log4j.appender.fatalAppender.layout=org.apache.log4j.PatternLayout
+#Group=FatalLogger
+#Description=The conversion pattern for the fatal logger
log4j.appender.fatalAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=FatalLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-fatal=FATAL, fatalAppender
+#Group=FatalLogger
+#Description=The maximum file size for the fatal logger
log4j.appender.fatalAppender.MaxFileSize=500KB
+#Group=FatalLogger
+#Description=The class responsible for appending text in the fatal logger
log4j.appender.fatalAppender=org.apache.log4j.RollingFileAppender
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties.template
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties.template
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/log4j.properties.template
2008-02-06 15:41:34 UTC (rev 3320)
@@ -3,60 +3,145 @@
## project : perfSONAR
## author: romradz
+#Group=Logger
+#Description=location of the log directory
+logDir=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs
-logDir=_LOGPATH_
-
#ROOT
-#log4j.appender.rootAppender.MaxBackupIndex=11
-#log4j.appender.rootAppender.File=_LOGPATH_/perfsonar.log
-#log4j.appender.rootAppender.layout=org.apache.log4j.PatternLayout
-#log4j.appender.rootAppender.layout.ConversionPattern=%d %5p - %m%n
-#log4j.rootLogger=DEBUG, rootAppender
-#log4j.appender.rootAppender.MaxFileSize=500KB
-#log4j.appender.rootAppender=org.apache.log4j.RollingFileAppender
+#Group=RootLogger
+#Description=The maximum backup index for the root logger
+log4j.appender.rootAppender.MaxBackupIndex=11
+#Group=RootLogger
+#Description=The file for the root logger
+log4j.appender.rootAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar.log
+#Group=RootLogger
+#Description=The class responsible for the layout of the root logger
+log4j.appender.rootAppender.layout=org.apache.log4j.PatternLayout
+#Group=RootLogger
+#Description=The conversion pattern for the root logger
+log4j.appender.rootAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=RootLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
+log4j.rootLogger=DEBUG, rootAppender
+#Group=RootLogger
+#Description=The maximum file size for the root logger
+#og4j.appender.rootAppender.MaxFileSize=500KB
+#Group=RootLogger
+#Description=The class responsible for appending text in the root logger
+log4j.appender.rootAppender=org.apache.log4j.RollingFileAppender
#DEBUG
+#Group=DebugLogger
+#Description=The maximum backup index for the debug logger
log4j.appender.debugAppender.MaxBackupIndex=11
-log4j.appender.debugAppender.File=_LOGPATH_/perfsonar_debug.log
+#Group=DebugLogger
+#Description=The file for the debug logger
+log4j.appender.debugAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_debug.log
+#Group=DebugLogger
+#Description=The class responsible for the layout of the debug logger
log4j.appender.debugAppender.layout=org.apache.log4j.PatternLayout
+#Group=DebugLogger
+#Description=The conversion pattern for the debug logger
log4j.appender.debugAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=DebugLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-debug=DEBUG, debugAppender
+#Group=DebugLogger
+#Description=The maximum file size for the debug logger
log4j.appender.debugAppender.MaxFileSize=500KB
+#Group=DebugLogger
+#Description=The class responsible for appending text in the debug logger
log4j.appender.debugAppender=org.apache.log4j.RollingFileAppender
#INFO
+#Group=InfoLogger
+#Description=The maximum backup index for the info logger
log4j.appender.infoAppender.MaxBackupIndex=11
-log4j.appender.infoAppender.File=_LOGPATH_/perfsonar_info.log
+#Group=InfoLogger
+#Description=The file for the info logger
+log4j.appender.infoAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_info.log
+#Group=InfoLogger
+#Description=The class responsible for the layout of the info logger
log4j.appender.infoAppender.layout=org.apache.log4j.PatternLayout
+#Group=InfoLogger
+#Description=The conversion pattern for the info logger
log4j.appender.infoAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=InfoLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-info=INFO, infoAppender
+#Group=InfoLogger
+#Description=The maximum file size for the info logger
log4j.appender.infoAppender.MaxFileSize=500KB
+#Group=InfoLogger
+#Description=The class responsible for appending text in the info logger
log4j.appender.infoAppender=org.apache.log4j.RollingFileAppender
#WARN
+#Group=WarnLogger
+#Description=The maximum backup index for the warning logger
log4j.appender.warnAppender.MaxBackupIndex=11
-log4j.appender.warnAppender.File=_LOGPATH_/perfsonar_warn.log
+#Group=WarnLogger
+#Description=The file for the warning logger
+log4j.appender.warnAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_warn.log
+#Group=WarnLogger
+#Description=The class responsible for the layout of the warning logger
log4j.appender.warnAppender.layout=org.apache.log4j.PatternLayout
+#Group=WarnLogger
+#Description=The conversion pattern for the warning logger
log4j.appender.warnAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=WarnLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-warn=WARN, warnAppender
+#Group=WarnLogger
+#Description=The maximum file size for the warning logger
log4j.appender.warnAppender.MaxFileSize=500KB
+#Group=WarnLogger
+#Description=The class responsible for appending text in the warning logger
log4j.appender.warnAppender=org.apache.log4j.RollingFileAppender
#ERROR
+#Group=ErrorLogger
+#Description=The maximum backup index for the error logger
log4j.appender.errorAppender.MaxBackupIndex=11
-log4j.appender.errorAppender.File=_LOGPATH_/perfsonar_error.log
+#Group=ErrorLogger
+#Description=The file for the error logger
+log4j.appender.errorAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_error.log
+#Group=ErrorLogger
+#Description=The class responsible for the layout of the error logger
log4j.appender.errorAppender.layout=org.apache.log4j.PatternLayout
+#Group=ErrorLogger
+#Description=The conversion pattern for the error logger
log4j.appender.errorAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=ErrorLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-error=ERROR, errorAppender
+#Group=ErrorLogger
+#Description=The maximum file size for the error logger
log4j.appender.errorAppender.MaxFileSize=500KB
+#Group=ErrorLogger
+#Description=The class responsible for appending text in the error logger
log4j.appender.errorAppender=org.apache.log4j.RollingFileAppender
#FATAL
+#Group=FatalLogger
+#Description=The maximum backup index for the fatal logger
log4j.appender.fatalAppender.MaxBackupIndex=11
-log4j.appender.fatalAppender.File=_LOGPATH_/perfsonar_fatal.log
+#Group=FatalLogger
+#Description=The file for the fatal logger
+log4j.appender.fatalAppender.File=/home/perfsonar/webapps/geant2_java-sshtelnet-mp-1.3RC1/WEB-INF/logs/perfsonar_fatal.log
+#Group=FatalLogger
+#Description=The class responsible for the layout of the fatal logger
log4j.appender.fatalAppender.layout=org.apache.log4j.PatternLayout
+#Group=FatalLogger
+#Description=The conversion pattern for the fatal logger
log4j.appender.fatalAppender.layout.ConversionPattern=%d %5p - %m%n
+#Group=FatalLogger
+#Description=Information specific to the perfsonar debugger (not sure of
this one at all really)
log4j.logger.sonar-fatal=FATAL, fatalAppender
+#Group=FatalLogger
+#Description=The maximum file size for the fatal logger
log4j.appender.fatalAppender.MaxFileSize=500KB
+#Group=FatalLogger
+#Description=The class responsible for appending text in the fatal logger
log4j.appender.fatalAppender=org.apache.log4j.RollingFileAppender
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.class
===================================================================
(Binary files differ)
Modified: branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,11 +1,102 @@
-#This file was created by the ant script.
-#Thu Feb 01 10:28:02 CET 2007
-service.r.type=mp
-component.registrator.interval=30000
-service.r.service_name=Java SSH Telnet MP
-service.ls.registration_file=
-service.mp.message_types=SetupDataRequest,MetadataKeyRequest,EchoRequest
-service.r.service_type=SSH/Telnet MP
-service.r.ls_url=
-service.r.service_description=Java SSH/Telnet MP, perfSONAR project
-component.registrator.scheduler_component=scheduler
\ No newline at end of file
+#Changed at Wed Jan 30 11:12:44 CET 2008
+#Wed Jan 30 11:12:44 CET 2008
+
+#Group=Global
+#Description=Type of service
+service.r.service_type=mp
+
+#Group=Global
+#Description=Description for the service
+service.r.service_description=perfSONAR service
+
+#Group=eXist
+#Description=The password for the admin account for eXist
+component.mp.xmldb.db_adminpassword=admin
+
+#Group=eXist
+#Description=The username for eXist
+component.mp.xmldb.db_username=sshtelnet
+
+#Group=logger
+#Description=The location of the configuration file for the log4j logger
+service.log.log4j.config=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/log4j.properties
+
+#Group=LS
+#Description=Location of the Lookup Service
+service.r.ls_url=http\://selena.acad.bg\:8070/axis/services/LookupService
+
+#Group=Global
+#Description=Type of service
+service.r.type=mp
+
+#Group=AuthN
+#Description=Location of the Authentication Service
+service.as.point=http\://homer.rediris.es\:8080/perfSONAR-AS/services/AuthService
+
+#Group=Scheduler
+#Description=The scheduler component
+component.registrator.scheduler_component=scheduler
+
+#Group=eXist
+#Description=The location of the metadata configuration file which is to be
uploaded in the eXist
+component.mp.xmldb.metadata_file_name=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/sshtelnetmetadata.xml
+
+#Group=LS
+#Description=The period of time between registrations to the LS
+component.registrator.interval=30000
+
+#Group=SSHTELNET
+#Description=The name of the class which is responsible for handling the
requests
+service.mp.class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.WebserviceEngineAdapter
+
+#Group=eXist
+#Description=The url of the eXist db
+component.mp.xmldb.db_uri=xmldb\:exist\://127.0.0.1\:8080/exist/xmlrpc/db/db/
+
+#Group=eXist
+#Description=The url of the eXist db (probably a redundant parameter, but
nevertheless still in there, will be removed in the near future)
+component.mp.xmldb.db_uri.xmlrpc=xmldb\:exist\://localhost\:8080/exist/xmlrpc/db
+
+#Group=Global
+#Description=The name of the organisation which deployed the MP
+service.r.organization_name=
+
+#Group=eXist
+#Description=The password for the eXist database
+component.mp.xmldb.db_password=sshtelnet
+
+#Group=SAX
+#Description=The location of the configuration for the SAX parser
+service.sax_parser.config=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/objects.config
+
+#Group=eXist
+#Description=The type of access for the eXist database (has to be xmlrpc)
+component.mp.xmldb.db_access=xmlrpc
+
+#Group=LS
+#Description=The name of the metadata configuration file which is to be sent
to the LS
+service.ls.registration_file=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/sshtelnetmetadata.xml
+
+#Group=Global
+#Description=The name of the service
+service.r.service_name=JAVA-SSHTELNET-MP
+
+#Group=AuthN
+#Description=The types of messages for which AuthN is to be enabled (if
AuthN is enabled off course)
+service.as.authn_for_msg_types=SetupDataRequest,MetadataKeyRequest
+
+#Group=Global
+#Description=The version of the service
+service.r.service_version=1.3RC1
+
+#Group=AuthN
+#Description=If the authentication is enabled or not
+service.as.authn_active=on
+
+#Group=Global
+#Description=The e-mail address of the contact person for the service
+service.r.contact_email=
+
+#Group=SSHTELNET
+#Description=Types of messages supported by this service
+service.mp.message_types=SetupDataRequest,MetadataKeyRequest,EchoRequest
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties.template
===================================================================
--- branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties.template
2008-02-06 15:18:55 UTC (rev 3319)
+++ branches/geant2_java-sshtelnet-mp-STABLE/conf/service.properties.template
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,11 +1,102 @@
-#This file was created by the ant script.
-#Thu Feb 01 10:28:02 CET 2007
+#Changed at Wed Jan 30 11:12:44 CET 2008
+#Wed Jan 30 11:12:44 CET 2008
+
+#Group=Global
+#Description=Type of service
+service.r.service_type=mp
+
+#Group=Global
+#Description=Description for the service
+service.r.service_description=perfSONAR service
+
+#Group=eXist
+#Description=The password for the admin account for eXist
+component.mp.xmldb.db_adminpassword=admin
+
+#Group=eXist
+#Description=The username for eXist
+component.mp.xmldb.db_username=sshtelnet
+
+#Group=logger
+#Description=The location of the configuration file for the log4j logger
+service.log.log4j.config=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/log4j.properties
+
+#Group=LS
+#Description=Location of the Lookup Service
+service.r.ls_url=http\://selena.acad.bg\:8070/axis/services/LookupService
+
+#Group=Global
+#Description=Type of service
service.r.type=mp
+
+#Group=AuthN
+#Description=Location of the Authentication Service
+service.as.point=http\://homer.rediris.es\:8080/perfSONAR-AS/services/AuthService
+
+#Group=Scheduler
+#Description=The scheduler component
+component.registrator.scheduler_component=scheduler
+
+#Group=eXist
+#Description=The location of the metadata configuration file which is to be
uploaded in the eXist
+component.mp.xmldb.metadata_file_name=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/sshtelnetmetadata.xml
+
+#Group=LS
+#Description=The period of time between registrations to the LS
component.registrator.interval=30000
-service.r.service_name=Java SSH Telnet MP
-service.ls.registration_file=
+
+#Group=SSHTELNET
+#Description=The name of the class which is responsible for handling the
requests
+service.mp.class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.WebserviceEngineAdapter
+
+#Group=eXist
+#Description=The url of the eXist db
+component.mp.xmldb.db_uri=xmldb\:exist\://127.0.0.1\:8080/exist/xmlrpc/db/db/
+
+#Group=eXist
+#Description=The url of the eXist db (probably a redundant parameter, but
nevertheless still in there, will be removed in the near future)
+component.mp.xmldb.db_uri.xmlrpc=xmldb\:exist\://localhost\:8080/exist/xmlrpc/db
+
+#Group=Global
+#Description=The name of the organisation which deployed the MP
+service.r.organization_name=
+
+#Group=eXist
+#Description=The password for the eXist database
+component.mp.xmldb.db_password=sshtelnet
+
+#Group=SAX
+#Description=The location of the configuration for the SAX parser
+service.sax_parser.config=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/objects.config
+
+#Group=eXist
+#Description=The type of access for the eXist database (has to be xmlrpc)
+component.mp.xmldb.db_access=xmlrpc
+
+#Group=LS
+#Description=The name of the metadata configuration file which is to be sent
to the LS
+service.ls.registration_file=/home/perfsonar/webapps/JAVA-SSHTELNET-MP-1.3-RC1/WEB-INF/classes/perfsonar/conf/sshtelnetmetadata.xml
+
+#Group=Global
+#Description=The name of the service
+service.r.service_name=JAVA-SSHTELNET-MP
+
+#Group=AuthN
+#Description=The types of messages for which AuthN is to be enabled (if
AuthN is enabled off course)
+service.as.authn_for_msg_types=SetupDataRequest,MetadataKeyRequest
+
+#Group=Global
+#Description=The version of the service
+service.r.service_version=1.3RC1
+
+#Group=AuthN
+#Description=If the authentication is enabled or not
+service.as.authn_active=on
+
+#Group=Global
+#Description=The e-mail address of the contact person for the service
+service.r.contact_email=
+
+#Group=SSHTELNET
+#Description=Types of messages supported by this service
service.mp.message_types=SetupDataRequest,MetadataKeyRequest,EchoRequest
-service.r.service_type=SSH/Telnet MP
-service.r.ls_url=
-service.r.service_description=Java SSH/Telnet MP, perfSONAR project
-component.registrator.scheduler_component=scheduler
Added: branches/geant2_java-sshtelnet-mp-STABLE/conf/servlet.properties
Added:
branches/geant2_java-sshtelnet-mp-STABLE/conf/servlet.properties.template
Added: branches/geant2_java-sshtelnet-mp-STABLE/doc/Functionality
Specification for SSHTelnet 1.3.doc
Property changes on:
branches/geant2_java-sshtelnet-mp-STABLE/doc/Functionality Specification for
SSHTelnet 1.3.doc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/geant2_java-sshtelnet-mp-STABLE/doc/Interface Specification
for SSHTelnet 1.3.doc
Property changes on: branches/geant2_java-sshtelnet-mp-STABLE/doc/Interface
Specification for SSHTelnet 1.3.doc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: branches/geant2_java-sshtelnet-mp-STABLE/doc/Metadata Configuration
file for SSHTelnet 1.3.doc
Property changes on: branches/geant2_java-sshtelnet-mp-STABLE/doc/Metadata
Configuration file for SSHTelnet 1.3.doc
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/commands-complete-list-v5-SM.xls
Property changes on:
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/commands-complete-list-v5-SM.xls
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/commands_minimum_set-v5-SM.xls
Property changes on:
branches/geant2_java-sshtelnet-mp-STABLE/doc/commands/commands_minimum_set-v5-SM.xls
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added:
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/MetadataKeyRequest.rnc
Added:
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/MetadataKeyResponse.rnc
Added:
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/SetupDataRequest.rnc
Added:
branches/geant2_java-sshtelnet-mp-STABLE/doc/schema/SetupDataResponse.rnc
Added:
branches/geant2_java-sshtelnet-mp-STABLE/samples/sshtelnetmptemplate.csv
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,16 +1,15 @@
/*
* Created on Jan 5, 2005
- * Version Number: 0.1
+ * Updated on Jan 8, 2008
+ * Version Number: 1.0
* Project: perfSonar
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp;
import java.util.List;
-
import org.perfsonar.base.exceptions.PerfSONARException;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
-
/**
* Interface to which device ip bgp statistics providers should adhere
*
@@ -20,53 +19,51 @@
*
*/
public interface BgpAdapterInterface {
-
- // ---------------------- interface methods
-
- /**
- * Interface method to query about the device specific command
available
- *
- * @return List All specific StatusCommands for the device
- */
- public abstract List getAvailableSpecificCommands() ;
-
- /**
- * Sets the list with all specific commands available for that device
- *
- * @param availableSpecificCommands
- */
- public abstract void setAvailableSpecificCommands(List
availableSpecificCommands) ;
- /**
- * Adds a specific command to the list of available specific commands
- *
- * @param command
- */
- public abstract void addAvailableSpecificCommand(BgpCommandInterface
command) ;
-
- /**
- * Searches for a command supported by the device matching the given
- * description
- *
- * @param description
- * @return BgpCommandInterface representing the desirec command
- */
- public abstract BgpCommandInterface getCommand(String description)
throws PerfSONARException;
-
- /**
- * Executes the provided command on the remote device
- *
- *
- * @param command The BgpCommand to be executed command
- * @return BgpCommand with the results inserted
- */
- public abstract BgpCommandInterface
executeCommand(BgpCommandInterface command) ;
-
- /**
- * Makes the Adapter connecting to the device
- *
- */
- public abstract void connect() ;
-
- //List of commands that should be available to all status MP to be
included below
+ // ---------------------- interface methods
+ /**
+ * Interface method to query about the device specific command available
+ *
+ * @return List All specific StatusCommands for the device
+ */
+ public abstract List getAvailableSpecificCommands();
+
+ /**
+ * Sets the list with all specific commands available for that device
+ *
+ * @param availableSpecificCommands
+ */
+ public abstract void setAvailableSpecificCommands(List
availableSpecificCommands);
+
+ /**
+ * Adds a specific command to the list of available specific commands
+ *
+ * @param command
+ */
+ public abstract void addAvailableSpecificCommand(BgpCommandInterface
command);
+
+ /**
+ * Searches for a command supported by the device matching the given
+ * description
+ *
+ * @param description
+ * @return BgpCommandInterface representing the desirec command
+ */
+ public abstract BgpCommandInterface getCommand(String description)
throws PerfSONARException;
+
+ /**
+ * Executes the provided command on the remote device
+ *
+ *
+ * @param command The BgpCommand to be executed command
+ * @return BgpCommand with the results inserted
+ */
+ public abstract BgpCommandInterface executeCommand(BgpCommandInterface
command);
+
+ /**
+ * Makes the Adapter connecting to the device
+ *
+ */
+ public abstract void connect();
+ //List of commands that should be available to all status MP to be
included below
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2009
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,7 +20,6 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
@@ -29,7 +27,10 @@
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.telnet.TelnetManager;
@@ -44,622 +45,559 @@
*/
public class CiscoBgpAdapter implements BgpAdapterInterface, ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoBgpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- // ---------------------- class-fields
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ } catch (PerfSONARException e) {
- private RemoteManager manager = null;
+
logger.error("[CISCOBGPADAPTER][Constructor]"+e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private LoggerComponent logger = null;
+ }
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[CiscoBgpAdapter] Constructor started");
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoBgpAdapter] Constructor finished");
- // ---------------------- constructors
+ }// CiscoBgpAdapter
- public CiscoBgpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[CiscoBgpAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[CiscoBgpAdapter] setAvailableSpecificCommand called");
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoBgpAdapter] addAvailableSpecificCommand called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoBgpAdapter] Constructor started");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- logger.debug("[CiscoBgpAdapter] Constructor finished");
+ logger.debug("[CiscoBgpAdapter] getCommand called");
- }// CiscoBgpAdapter
+ BgpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- // ---------------------- public methods
+ while (it.hasNext()) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ command = (BgpCommand) it.next();
- logger.debug("[CiscoBgpAdapter] getAvailableSpecificCommands
called");
+ if (command.getDescription().equalsIgnoreCase(description)) {
- return availableSpecificCommands;
+ logger.debug("[CiscoBgpAdapter] Command found");
+ return command;
- }// getAvailableSpecificCommands
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while
- logger.debug("[CiscoBgpAdapter] setAvailableSpecificCommand
called");
+ logger.error("[CiscoBgpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- this.availableSpecificCommands = availableSpecificCommands;
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface executeCommand(BgpCommandInterface command) {
- }// setAvailableSpecificCommands
+ logger.debug("[CiscoBgpAdapter] executeCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void addAvailableSpecificCommand(BgpCommandInterface command) {
+ if (manager != null) {
- logger.debug("[CiscoBgpAdapter] addAvailableSpecificCommand
called");
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");
- availableSpecificCommands.add(command);
+ manager.disconnect();
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[CiscoBgpAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoBgpAdapter] executeCommand finished");
+ return command;
- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (BgpCommand) it.next();
+ logger.info("[CiscoBgpAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[CiscoBgpAdapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
- }// while
+ //System.out.println(username);
+ //System.out.println(password);
- logger.error("[CiscoBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- }// getCommand
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ logger.info("[CiscoBgpAdapter] Trying to connect");
- logger.debug("[CiscoBgpAdapter] executeCommand called");
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- if (manager != null) {
+ logger.info("[CiscoBgpAdapter Login");
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
+ } catch (Exception e) {
- manager.disconnect();
+ logger.error("[CiscoBgpAdapter][Connect] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }
- }// if
+ }// connect
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoBgpAdapter] executeCommand finished");
- return command;
+ // ---------------------- field methods
+ public int getPort() {
- }// executeCommand
+ return port;
- public void connect() {
- }
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public void setPort(int port) {
- logger.info("[CiscoBgpAdapter] Connect called");
+ this.port = port;
- try {
+ }
- if (manager == null) {
+ public String getPrompt() {
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ return prompt;
- //System.out.println(username);
- //System.out.println(password);
+ }
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ public void setPrompt(String prompt) {
- }
+ this.prompt = prompt;
- logger.info("[CiscoBgpAdapter] Trying to connect");
+ }
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ public String getUrl() {
- logger.info("[CiscoBgpAdapter Login");
+ return url;
- } catch (Exception e) {
+ }
- logger.error("[CiscoBgpAdapter] Error occuring while
connecting");
- //System.err.println("[CiscoBgpAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[CiscoBgpAdapter] Configuring available operations
...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("BGP")) {
- }
+ BgpCommand command = new BgpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+
logger.debug("service.mp."+subject+".commands."+token+".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOBGPADAPTER][ConfigureCommands]"+e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOBGPADAPTER][ConfigureCommands]"+e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+
logger.error("[CISCOBGPADAPTER][ConfigureCommands]"+e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ logger.debug("[CiscoBgpAdapter] Available operations configured");
- return url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, BgpCommandInterface bgpCommand)
{
- public void setUrl(String url) {
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- this.url = url;
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- }
+ }
- // ---------------------- Private methods
+ String tempResult = temp.substring((bgpCommand.getCommand() + " "
+ bgpCommand.getParameterString()).length());
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- logger.debug("[CiscoBgpAdapter] Configuring available
operations ...");
+ StringBuffer resultBuffer = new StringBuffer(t2);
- StringTokenizer tokenizer = null;
- String token = null;
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- try {
+ t2 = resultBuffer.toString();
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ return t2.replace("" + prompt, "---END---");
- token = tokenizer.nextToken();
- if (token.contains("BGP")) {
+ }
- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- }
+ }
- } catch (PerfSONARException e) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ logger.info("[CiscoBgpAdapter] Webservice takeAction call received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- logger.debug("[CiscoBgpAdapter] Available operations
configured");
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, BgpCommandInterface
bgpCommand) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ CiscoBgpAdapter adapter = new CiscoBgpAdapter();
- }
+ // REPLACED
- String tempResult = temp
- .substring((bgpCommand.getCommand() + " " +
bgpCommand
-
.getParameterString()).length());
+ availableSpecificCommands = new ArrayList();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ try {
- StringBuffer resultBuffer = new StringBuffer(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+
+ manager = new TelnetManager(url, port, false, timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ } catch (NumberFormatException e1) {
- t2 = resultBuffer.toString();
+
logger.error("[CISCOBGPADAPTER][TakeAction]"+e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return t2.replace("" + prompt, "---END---");
+ } catch (PerfSONARException e1) {
- }
+
logger.error("[CISCOBGPADAPTER][TakeAction]"+e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // ---------------------- Methods from service engine interface
+ }
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.debug("[CiscoStatusAdapter] TelnetManager created: " + url +
" " + port);
- return this.serviceEngineType;
+ try {
- }
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ } catch (PerfSONARException e) {
- logger.info("[CiscoBgpAdapter] Webservice takeAction call
received");
+
logger.error("[CISCOBGPADAPTER][TakeAction]"+e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ }
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ logger.debug("[CiscoStatusAdapter] Prompt set in TelnetManager: " +
prompt);
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ //
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);
- CiscoBgpAdapter adapter = new CiscoBgpAdapter();
- //adapter.connect(subject);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- // REPLACED
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- availableSpecificCommands = new ArrayList();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- try {
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ bgpCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- manager = new TelnetManager(url, port, false);
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {
- } catch (NumberFormatException e1) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();
- } catch (PerfSONARException e1) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- logger.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- try {
+ }
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ }
- } catch (PerfSONARException e) {
+ if (temp.equalsIgnoreCase("")) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();
- }
+ }
- logger.debug("[CiscoStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ } else if (bgpCommand.getMinParamCount() == 0) {
- //
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- BgpCommandInterface bgpCommand =
this.getCommand(eventTypeString);
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- bgpCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- if (bgpCommand.getParameters().size() >= bgpCommand
- .getMinParamCount()
- && bgpCommand.getParameters().size()
<= bgpCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();
- } else if (bgpCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[CiscoBgpAdapter] Command executed succesfully");
- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[CiscoBgpAdapter] Command executed succesfully");
+ logger.info("[CiscoBgpAdapter] Constructing response message");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, bgpCommand));
- else
- datum.setDatum(temp);
+ Message response = new Message();
- logger.info("[CiscoBgpAdapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.info("[CiscoBgpAdapter] takeAction finished");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ return response;
- logger.info("[CiscoBgpAdapter] takeAction finished");
+ }
- return response;
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ CiscoBgpAdapter adapter = new CiscoBgpAdapter();
- // ---------------------- Stand-alond Test Method
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco1");
- public static void main(String[] args) {
+ adapter.connect("cisco1");
- try {
- CiscoBgpAdapter adapter = new CiscoBgpAdapter();
+ BgpCommandInterface bgpCommand;
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco1");
- //System.out.println("1");
+ try {
- adapter.connect("cisco1");
- //System.out.println("2");
+ bgpCommand = adapter.getCommand("BGP");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- BgpCommandInterface bgpCommand;
- //System.out.println("3");
+ } catch (PerfSONARException e) {
- try {
+ //e.printStackTrace();
- bgpCommand = adapter.getCommand("BGP");
- //System.out.println("4");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- //System.out.println("5");
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters;
@@ -8,8 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
-
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
import org.ggf.ns.nmwg.base.v2_0.EventType;
@@ -21,7 +19,6 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
@@ -29,7 +26,10 @@
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshKeyManager;
@@ -44,603 +44,543 @@
*/
public class CiscoKeyBgpAdapter implements BgpAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoKeyBgpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
-
- private String passphrase = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOKEYBGPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoKeyBgpAdapter] Constructor finished");
- // ---------------------- constructors
+ }// CiscoKeyBgpAdapter
- public CiscoKeyBgpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[CiscoKeyBgpAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[CiscoKeyBgpAdapter] setAvailableSpecificCommand
called");
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoKeyBgpAdapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoKeyBgpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoKeyBgpAdapter
+ logger.debug("[CiscoKeyBgpAdapter] getCommand called");
- // ---------------------- public methods
+ BgpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[CiscoKeyBgpAdapter]
getAvailableSpecificCommands called");
+ command = (BgpCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoKeyBgpAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger
- .debug("[CiscoKeyBgpAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoKeyBgpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface executeCommand(BgpCommandInterface command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void addAvailableSpecificCommand(BgpCommandInterface command) {
+ logger.debug("[CiscoKeyBgpAdapter] executeCommand called");
- logger
- .debug("[CiscoKeyBgpAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ logger.info("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[CiscoKeyBgpAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (BgpCommand) it.next();
+ logger.info("[CiscoKeyBgpAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[CiscoKeyBgpAdapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+
+ if (passphrase == null || passphrase.equals("")) {
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ } else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+ }
- }// while
+ logger.info("[CiscoKeyBgpAdapter] Trying to connect");
- logger.error("[CiscoKeyBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ //if (passphrase == null || passphrase.equals("")) {
+ //manager.connect(username, keyUrl);
+ //} else {
+ //manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[CiscoKeyBgpAdapter] Login");
- }// getCommand
+ } catch (Exception e) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ logger.error("[CiscoKeyBgpAdapter][Connect] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
+ }
- logger.debug("[CiscoKeyBgpAdapter] executeCommand called");
+ }// connect
- if (manager != null) {
+ // ---------------------- field methods
+ public int getPort() {
- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ return port;
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }
- }// if
+ public void setPort(int port) {
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ this.port = port;
- }// executeCommand
+ }
- public void connect() {
- }
+ public String getPrompt() {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ return prompt;
- logger.info("[CiscoKeyBgpAdapter] Connect called");
+ }
- try {
+ public void setPrompt(String prompt) {
- if (manager == null) {
+ this.prompt = prompt;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ public String getUrl() {
- }
+ return url;
- logger.info("[CiscoKeyBgpAdapter] Trying to connect");
+ }
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[CiscoKeyBgpAdapter] Login");
+ public void setUrl(String url) {
- } catch (Exception e) {
+ this.url = url;
- logger
- .info("[CiscoKeyBgpAdapter] Error
occuring while connecting");
- // System.err.println("[CiscoKeyBgpAdapter] Error
occuring while
- // connecting");
- logger.info(e.getStackTrace().toString());
- // System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
- }
+ }
- }// connect
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- // ---------------------- field methods
+ logger.debug("[CiscoKeyBgpAdapter] Configuring available operations
...");
- public int getPort() {
+ Iterator commands = null;
+ String token = null;
- return port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public void setPort(int port) {
+ token = (String) commands.next();
+ if (token.contains("BGP")) {
- this.port = port;
+ BgpCommand command = new BgpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CiscoKeyBgpAdapter][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CiscoKeyBgpAdapter][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public String getPrompt() {
+ }
- return prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public void setPrompt(String prompt) {
+ logger.error("[CiscoKeyBgpAdapter][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- this.prompt = prompt;
+ }
- }
+ logger.debug("[CiscoKeyBgpAdapter] Available operations configured");
- public String getUrl() {
+ }
- return url;
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, BgpCommandInterface bgpCommand)
{
- }
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- public void setUrl(String url) {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- this.url = url;
+ }
- }
+ String tempResult = temp.substring((bgpCommand.getCommand() + " "
+ bgpCommand.getParameterString()).length());
- // ---------------------- Private methods
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- logger
- .debug("[CiscoKeyBgpAdapter] Configuring
available operations ...");
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ t2 = resultBuffer.toString();
- try {
+ return t2.replace("" + prompt, "---END---");
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ }
- token = tokenizer.nextToken();
- if (token.contains("BGP")) {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ return this.serviceEngineType;
- }
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- } catch (PerfSONARException e) {
+ logger.info("[CiscoKeyBgpAdapter] Webservice takeAction call
received");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- }
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- logger.debug("[CiscoKeyBgpAdapter] Available operations
configured");
+ logger.debug("SUBJECTSTRING: " + subject);
- }
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, BgpCommandInterface
bgpCommand) {
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ //CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();
- }
+ availableSpecificCommands = new ArrayList();
- String tempResult = temp
- .substring((bgpCommand.getCommand() + " " +
bgpCommand
-
.getParameterString()).length());
+ try {
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ } catch (NumberFormatException e1) {
- t2 = resultBuffer.toString();
+ logger.error("[CiscoKeyBgpAdapter][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return t2.replace("" + prompt, "---END---");
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[CiscoKeyBgpAdapter][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // ---------------------- Methods from service engine interface
+ }
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.debug("[CiscoKeyBgpAdapter] TelnetManager created: " + url +
" " + port);
- return this.serviceEngineType;
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- }
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- logger
- .info("[CiscoKeyBgpAdapter] Webservice
takeAction call received");
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ bgpCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();
- //adapter.connect(subject);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- availableSpecificCommands = new ArrayList();
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- username = properties.getProperty("service.r.mp." +
subject
- + ".username");
- keyUrl = properties.getProperty("service.r.mp." +
subject
- + ".keyUrl");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ }
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (temp.equalsIgnoreCase("")) {
- } catch (PerfSONARException e1) {
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ }
- }
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- logger.debug("[CiscoKeyBgpAdapter] TelnetManager created: " +
url
- + " " + port);
+ } else if (bgpCommand.getMinParamCount() == 0) {
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- BgpCommandInterface bgpCommand =
this.getCommand(eventTypeString);
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- bgpCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- if (bgpCommand.getParameters().size() >= bgpCommand
- .getMinParamCount()
- && bgpCommand.getParameters().size()
<= bgpCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- } else if (bgpCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[CiscoKeyBgpAdapter] Command executed succesfully");
- }
+ Datum datum = new Datum();
- logger.info("[CiscoKeyBgpAdapter] Command executed
succesfully");
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Datum datum = new Datum();
+ logger.info("[CiscoKeyBgpAdapter] Constructing response message");
- if (valid)
- datum.setDatum(filterResult(temp, bgpCommand));
- else
- datum.setDatum(temp);
+ Message response = new Message();
- logger.info("[CiscoKeyBgpAdapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.info("[CiscoKeyBgpAdapter] takeAction finished");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ return response;
- logger.info("[CiscoKeyBgpAdapter] takeAction finished");
+ }
- return response;
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();
- // ---------------------- Stand-alond Test Method
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("junipernl");
- public static void main(String[] args) {
+ adapter.connect("junipernl");
- try {
- CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();
+ BgpCommandInterface bgpCommand;
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ try {
- adapter.connect("junipernl");
+ bgpCommand = adapter.getCommand("BGP_PEERING_STATUS");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- BgpCommandInterface bgpCommand;
+ //System.out.println(adapter.filterResult(temp, bgpCommand));
- try {
+ } catch (PerfSONARException e) {
- bgpCommand =
adapter.getCommand("BGP_PEERING_STATUS");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //e.printStackTrace();
- System.out.println(adapter.filterResult(temp,
bgpCommand));
-
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
- }
-
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters;
@@ -8,8 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
-
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
import org.ggf.ns.nmwg.base.v2_0.EventType;
@@ -21,7 +19,6 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
@@ -29,7 +26,10 @@
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshManager;
@@ -44,596 +44,547 @@
*/
public class CiscoSshBgpAdapter implements BgpAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
+
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String url = "";
+ // ---------------------- constructors
+ public CiscoSshBgpAdapter() throws PerfSONARException {
- private String prompt = "";
+ try {
- private int port = 0;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String username = "";
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private String password = "";
-
- private int caching = 0;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- // ---------------------- class-fields
+ } catch (PerfSONARException e) {
- private List availableSpecificCommands = null;
+ logger.error("[CISCOSSHBGPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private RemoteManager manager = null;
+ }
- private LoggerComponent logger = null;
+ logger.debug("[CiscoSshBgpAdapter] Constructor started");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[CiscoSshBgpAdapter] Constructor finished");
- private static List cachedResults = new ArrayList();
+ }// CiscoSshBgpAdapter
- // ---------------------- constructors
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- public CiscoSshBgpAdapter() throws PerfSONARException {
+ logger.debug("[CiscoSshBgpAdapter] getAvailableSpecificCommands
called");
- try {
+ return availableSpecificCommands;
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ logger.debug("[CiscoSshBgpAdapter] setAvailableSpecificCommand
called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {
- } catch (PerfSONARException e) {
+ logger.debug("[CiscoSshBgpAdapter] addAvailableSpecificCommand
called");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ availableSpecificCommands.add(command);
- }
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- logger.debug("[CiscoSshBgpAdapter] Constructor started");
+ logger.debug("[CiscoSshBgpAdapter] getCommand called");
- logger.debug("[CiscoSshBgpAdapter] Constructor finished");
+ BgpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- }// CiscoSshBgpAdapter
+ while (it.hasNext()) {
- // ---------------------- public methods
+ command = (BgpCommand) it.next();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ if (command.getDescription().equalsIgnoreCase(description)) {
- logger.debug("[CiscoSshBgpAdapter]
getAvailableSpecificCommands called");
+ logger.debug("[CiscoSshBgpAdapter] Command found");
+ return command;
- return availableSpecificCommands;
+ }
- }// getAvailableSpecificCommands
+ }// while
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.error("[CiscoSshBgpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- logger.debug("[CiscoSshBgpAdapter]
setAvailableSpecificCommand called");
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface executeCommand(BgpCommandInterface command) {
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.debug("[CiscoSshBgpAdapter] executeCommand called");
- }// setAvailableSpecificCommands
+ if (manager != null) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void addAvailableSpecificCommand(BgpCommandInterface command) {
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- logger.debug("[CiscoSshBgpAdapter]
addAvailableSpecificCommand called");
+ }// if
- availableSpecificCommands.add(command);
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshBgpAdapter] executeCommand finished");
+ return command;
- }// addAvailableSpecificCommand
+ }// executeCommand
+ public void connect() {
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- logger.debug("[CiscoSshBgpAdapter] getCommand called");
+ logger.info("[CiscoSshBgpAdapter] Connect called");
- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ try {
- while (it.hasNext()) {
+ if (manager == null) {
- command = (BgpCommand) it.next();
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ //System.out.println(username);
+ //System.out.println(password);
- logger.debug("[CiscoSshBgpAdapter] Command
found");
- return command;
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- }
+ }
- }// while
+ logger.info("[CiscoSshBgpAdapter] Trying to connect");
- logger.error("[CiscoSshBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- }// getCommand
+ logger.info("[CiscoSshBgpAdapter Login");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ } catch (Exception e) {
- logger.debug("[CiscoSshBgpAdapter] executeCommand called");
+ logger.error("[CiscoSshBgpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- if (manager != null) {
+ }
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }// connect
- }// if
+ // ---------------------- field methods
+ public int getPort() {
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshBgpAdapter] executeCommand finished");
- return command;
+ return port;
- }// executeCommand
+ }
- public void connect() {
- }
+ public void setPort(int port) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;
- logger.info("[CiscoSshBgpAdapter] Connect called");
+ }
- try {
+ public String getPrompt() {
- if (manager == null) {
+ return prompt;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- //System.out.println(username);
- //System.out.println(password);
+ public void setPrompt(String prompt) {
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ this.prompt = prompt;
- }
+ }
- logger.info("[CiscoSshBgpAdapter] Trying to connect");
+ public String getUrl() {
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ return url;
- logger.info("[CiscoSshBgpAdapter Login");
+ }
- } catch (Exception e) {
+ public void setUrl(String url) {
- logger.error("[CiscoSshBgpAdapter] Error occuring
while connecting");
- //System.err.println("[CiscoSshBgpAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ this.url = url;
- }
+ }
- }// connect
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- // ---------------------- field methods
+ logger.debug("[CiscoSshBgpAdapter] Configuring available operations
...");
- public int getPort() {
+ Iterator commands = null;
+ String token = null;
- return port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public void setPort(int port) {
+ token = (String) commands.next();
+ if (token.contains("BGP")) {
- this.port = port;
+ BgpCommand command = new BgpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public String getPrompt() {
+ }
- return prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public void setPrompt(String prompt) {
+ logger.error("[CISCOSSHBGPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- this.prompt = prompt;
+ }
- }
+ logger.debug("[CiscoSshBgpAdapter] Available operations configured");
- public String getUrl() {
+ }
- return url;
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, BgpCommandInterface bgpCommand)
{
- }
+ //logger.debug("result: " + temp);
+
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- public void setUrl(String url) {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- this.url = url;
+ }
- }
+ //String tempResult = temp
+ // .substring((bgpCommand.getCommand() + " " +
bgpCommand
+ // .getParameterString()).length());
- // ---------------------- Private methods
+ String t1 = temp.replaceAll("\\n", "");
+ String t2 = t1.replaceAll("\\r", "@@@");
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- logger.debug("[CiscoSshBgpAdapter] Configuring available
operations ...");
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ t2 = resultBuffer.toString();
- try {
+ return t2.replace("" + prompt, "---END---");
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ }
- token = tokenizer.nextToken();
- if (token.contains("BGP")) {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ return this.serviceEngineType;
- }
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- } catch (PerfSONARException e) {
+ logger.info("[CiscoSshBgpAdapter] Webservice takeAction call
received");
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- }
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- logger.debug("[CiscoSshBgpAdapter] Available operations
configured");
+ logger.debug("SUBJECTSTRING: " + subject);
- }
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, BgpCommandInterface
bgpCommand) {
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ //CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();
- }
+ // REPLACED
- String tempResult = temp;
-// .substring((bgpCommand.getCommand() + " " +
bgpCommand
-//
.getParameterString()).length());
+ availableSpecificCommands = new ArrayList();
- String t1 = tempResult.replaceAll("\\n", "");
- String t2 = t1.replaceAll("\\r", "@@@");
+ try {
- StringBuffer resultBuffer = new StringBuffer(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
-
- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {
- return t2.replace("" + prompt, "---END---");
+ logger.error("[CISCOSSHBGPADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- }
+ } catch (PerfSONARException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOSSHBGPADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ }
- return this.serviceEngineType;
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- }
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException{
+ //
- logger.info("[CiscoSshBgpAdapter] Webservice takeAction call
received");
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ bgpCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ }
- CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();
- //adapter.connect(subject);
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {
- // REPLACED
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- availableSpecificCommands = new ArrayList();
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();
- try {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- } catch (NumberFormatException e1) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ if (temp.equalsIgnoreCase("")) {
- }
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ }
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- //
+ } else if (bgpCommand.getMinParamCount() == 0) {
- BgpCommandInterface bgpCommand =
this.getCommand(eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- bgpCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- if (bgpCommand.getParameters().size() >= bgpCommand
- .getMinParamCount()
- && bgpCommand.getParameters().size()
<= bgpCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (bgpCommand.getMinParamCount() == 0) {
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ } else {
- } else {
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ logger.info("[CiscoSshBgpAdapter] Command executed succesfully");
+ logger.debug("" + valid);
- //System.out.println("[CiscoSshBgpAdapter] Command executed
succesfully");
- logger.info("[CiscoSshBgpAdapter] Command executed
succesfully");
- //System.out.println(valid);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, bgpCommand));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoSshBgpAdapter] Constructing response message");
- //System.out.println("[CiscoSshBgpAdapter] Constructing
response message");
- logger.info("[CiscoSshBgpAdapter] Constructing response
message");
+ Message response = new Message();
- Message response = new Message();
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[CiscoSshBgpAdapter] takeAction finished");
- logger.info("[CiscoSshBgpAdapter] takeAction finished");
+ return response;
- return response;
+ }
- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // ---------------------- Stand-alond Test Method
+ try {
+ CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();
- public static void main(String[] args) {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco2");
- try {
- CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();
+ adapter.connect("cisco2");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco2");
+ BgpCommandInterface bgpCommand;
- adapter.connect("cisco2");
+ try {
- BgpCommandInterface bgpCommand;
+ bgpCommand = adapter.getCommand("BGP");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println("Temp: " + temp);
- try {
+ } catch (PerfSONARException e) {
- bgpCommand = adapter.getCommand("BGP");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println("Temp: " + temp);
+ //e.printStackTrace();
- } catch (PerfSONARException e) {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters;
@@ -8,8 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
-
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
import org.ggf.ns.nmwg.base.v2_0.EventType;
@@ -21,7 +19,6 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
@@ -29,7 +26,10 @@
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.telnet.TelnetManager;
@@ -44,624 +44,565 @@
*/
public class JuniperBgpAdapter implements BgpAdapterInterface, ServiceEngine
{
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperBgpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[JUNIPERBGPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperBgpAdapter] Constructor finished");
- // ---------------------- constructors
+ }// JuniperBgpAdapter
- public JuniperBgpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[JuniperBgpAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperBgpAdapter] setAvailableSpecificCommand
called");
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[JuniperBgpAdapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperBgpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// JuniperBgpAdapter
+ logger.debug("[JuniperBgpAdapter] getCommand called");
- // ---------------------- public methods
+ BgpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[JuniperBgpAdapter]
getAvailableSpecificCommands called");
+ command = (BgpCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[JuniperBgpAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[JuniperBgpAdapter] setAvailableSpecificCommand
called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperBgpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface executeCommand(BgpCommandInterface command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void addAvailableSpecificCommand(BgpCommandInterface command) {
+ logger.debug("[JuniperStatusAdapter] executeCommand called");
- logger.debug("[JuniperBgpAdapter] addAvailableSpecificCommand
called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
- }// addAvailableSpecificCommand
+ String temp2 = manager.executeCommand(" ");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ manager.disconnect();
- logger.debug("[JuniperBgpAdapter] getCommand called");
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// if
- while (it.hasNext()) {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- command = (BgpCommand) it.next();
+ }// executeCommand
+ public void connect() {
+ }
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- logger.debug("[JuniperBgpAdapter] Command
found");
- return command;
+ logger.info("[JuniperBgpAdapter] Connect called");
- }
+ try {
- }// while
+ if (manager == null) {
- logger.error("[JuniperBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// getCommand
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ }
- logger.debug("[JuniperStatusAdapter] executeCommand called");
+ logger.info("[JuniperBgpAdapter] Trying to connect");
- if (manager != null) {
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
+ manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ logger.info("[JuniperBgpAdapter] Login");
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ } catch (Exception e) {
- String temp2 = manager.executeCommand(" ");
+ logger.error("[JuniperBgpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- manager.disconnect();
+ }
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }// connect
- }// if
+ // ---------------------- field methods
+ public int getPort() {
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ return port;
- }// executeCommand
+ }
- public void connect() {
- }
+ public void setPort(int port) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;
- logger.info("[JuniperBgpAdapter] Connect called");
+ }
- try {
+ public String getPrompt() {
- if (manager == null) {
+ return prompt;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ public void setPrompt(String prompt) {
- }
+ this.prompt = prompt;
- logger.info("[JuniperBgpAdapter] Trying to connect");
+ }
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
- manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.info("[JuniperBgpAdapter] Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger.info("[JuniperBgpAdapter] Error occuring while
connecting");
- // System.err.println("[JuniperBgpAdapter] Error
occuring while
- // connecting");
- logger.info(e.getStackTrace().toString());
- // System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[JuniperBgpAdapter] Configuring available operations
...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("BGP")) {
- public String getPrompt() {
+ BgpCommand command = new BgpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[JUNIPERBGPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ logger.debug("[JuniperBgpAdapter] Available operations configured");
- }
+ }
- public void setUrl(String url) {
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, BgpCommandInterface bgpCommand)
{
- this.url = url;
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- }
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- // ---------------------- Private methods
+ }
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ while (temp.indexOf("---(more") > 0) {
- logger
- .debug("[JuniperBgpAdapter] Configuring
available operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- StringTokenizer tokenizer = null;
- String token = null;
+ }
- try {
+ String tempResult = temp.substring((bgpCommand.getCommand() + " "
+ bgpCommand.getParameterString()).length());
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- token = tokenizer.nextToken();
- if (token.contains("BGP")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- logger.debug("[JuniperBgpAdapter] Available operations
configured");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, BgpCommandInterface
bgpCommand) {
+ logger.info("[JuniperBgpAdapter] Webservice takeAction call
received");
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- while (temp.indexOf("---(more") > 0) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String tempResult = temp
- .substring((bgpCommand.getCommand() + " " +
bgpCommand
-
.getParameterString()).length());
+ JuniperBgpAdapter adapter = new JuniperBgpAdapter();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ availableSpecificCommands = new ArrayList();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ try {
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ // TODO::Should be specified on the Adapter Level
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- t2 = resultBuffer.toString();
+ manager = new TelnetManager(url, port, false, timeout);
- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {
- }
+ logger.error("[JUNIPERBGPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- // ---------------------- Methods from service engine interface
+ } catch (PerfSONARException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[JUNIPERBGPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- return this.serviceEngineType;
+ }
- }
+ logger.debug("[JuniperBgpAdapter] TelnetManager created: " + url + "
" + port);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ try {
- logger.info("[JuniperBgpAdapter] Webservice takeAction call
received");
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ } catch (PerfSONARException e) {
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ logger.error("[JUNIPERBGPADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ logger.debug("[JuniperBgpAdapter] Prompt set in TelnetManager: " +
prompt);
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- JuniperBgpAdapter adapter = new JuniperBgpAdapter();
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);
- //adapter.connect(subject);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- availableSpecificCommands = new ArrayList();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- try {
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- // TODO::Should be specified on the Adapter Level
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ bgpCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- manager = new TelnetManager(url, port, false);
+ }
- } catch (NumberFormatException e1) {
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- } catch (PerfSONARException e1) {
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.debug("[JuniperBgpAdapter] TelnetManager created: " +
url + " "
- + port);
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ }
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ if (temp.equalsIgnoreCase("")) {
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();
- logger.debug("[JuniperBgpAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ }
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- BgpCommandInterface bgpCommand =
this.getCommand(eventTypeString);
+ } else if (bgpCommand.getMinParamCount() == 0) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- bgpCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (bgpCommand.getParameters().size() >= bgpCommand
- .getMinParamCount()
- && bgpCommand.getParameters().size()
<= bgpCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (bgpCommand.getMinParamCount() == 0) {
+ if (temp.equalsIgnoreCase("")) {
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ }
- } else {
+ } else {
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- }
+ }
- logger.info("[JuniperBgpAdapter] Command executed
succesfully");
+ logger.info("[JuniperBgpAdapter] Command executed succesfully");
- Datum datum = new Datum();
+ Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, bgpCommand));
- else
- datum.setDatum(temp);
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[JuniperBgpAdapter] Constructing response
message");
+ logger.info("[JuniperBgpAdapter] Constructing response message");
- Message response = new Message();
+ Message response = new Message();
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- logger.info("[JuniperBgpAdapter] takeAction finished");
+ logger.info("[JuniperBgpAdapter] takeAction finished");
- return response;
+ return response;
- }
+ }
- // ---------------------- Stand-alond Test Method
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- public static void main(String[] args) {
+ try {
+ JuniperBgpAdapter adapter = new JuniperBgpAdapter();
- try {
- JuniperBgpAdapter adapter = new JuniperBgpAdapter();
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("juniper1");
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniper1");
+ adapter.connect("juniper1");
- adapter.connect("juniper1");
+ BgpCommandInterface bgpCommand;
- BgpCommandInterface bgpCommand;
+ try {
- try {
+ bgpCommand = adapter.getCommand("BGP_MULTICAST_ROUTE");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- bgpCommand =
adapter.getCommand("BGP_MULTICAST_ROUTE");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(adapter.filterResult(temp, bgpCommand));
- System.out.println(adapter.filterResult(temp,
bgpCommand));
+ } catch (PerfSONARException e) {
- } catch (PerfSONARException e) {
+ //e.printStackTrace();
- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 01.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters;
@@ -8,8 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
-
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
import org.ggf.ns.nmwg.base.v2_0.EventType;
@@ -21,7 +19,6 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
@@ -29,7 +26,10 @@
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshKeyManager;
@@ -44,616 +44,558 @@
*/
public class JuniperKeyBgpAdapter implements BgpAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperKeyBgpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
-
- private String passphrase = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- // ---------------------- class-fields
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ } catch (PerfSONARException e) {
- private RemoteManager manager = null;
+ logger.error("[JUNIPERKEYBGPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private LoggerComponent logger = null;
+ }
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[JuniperKeyBgpAdapter] Constructor finished");
- private static List cachedResults = new ArrayList();
+ }// JuniperKeyBgpAdapter
- // ---------------------- constructors
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- public JuniperKeyBgpAdapter() throws PerfSONARException {
+ logger.debug("[JuniperKeyBgpAdapter] getAvailableSpecificCommands
called");
- try {
+ return availableSpecificCommands;
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ logger.debug("[JuniperKeyBgpAdapter] setAvailableSpecificCommand
called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {
- } catch (PerfSONARException e) {
+ logger.debug("[JuniperKeyBgpAdapter] addAvailableSpecificCommand
called");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ availableSpecificCommands.add(command);
- }
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- logger.debug("[JuniperKeyBgpAdapter] Constructor finished");
+ logger.debug("[JuniperKeyBgpAdapter] getCommand called");
- }// JuniperKeyBgpAdapter
+ BgpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- // ---------------------- public methods
+ while (it.hasNext()) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ command = (BgpCommand) it.next();
- logger
- .debug("[JuniperKeyBgpAdapter]
getAvailableSpecificCommands called");
+ if (command.getDescription().equalsIgnoreCase(description)) {
- return availableSpecificCommands;
+ logger.debug("[JuniperKeyBgpAdapter] Command found");
+ return command;
- }// getAvailableSpecificCommands
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while
- logger
- .debug("[JuniperKeyBgpAdapter]
setAvailableSpecificCommand called");
+ logger.error("[JuniperKeyBgpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- this.availableSpecificCommands = availableSpecificCommands;
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface executeCommand(BgpCommandInterface command) {
- }// setAvailableSpecificCommands
+ logger.debug("[JuniperKeyBgpAdapter] executeCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void addAvailableSpecificCommand(BgpCommandInterface command) {
+ if (manager != null) {
- logger
- .debug("[JuniperKeyBgpAdapter]
addAvailableSpecificCommand called");
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- availableSpecificCommands.add(command);
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- }// addAvailableSpecificCommand
+ }// if
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- logger.debug("[JuniperKeyBgpAdapter] getCommand called");
+ }// executeCommand
+ public void connect() {
+ }
- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- while (it.hasNext()) {
+ logger.info("[JuniperKeyBgpAdapter] Connect called");
- command = (BgpCommand) it.next();
+ try {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {
- logger.debug("[JuniperKeyBgpAdapter] Command
found");
- return command;
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ if (passphrase == null || passphrase.equals("")) {
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ } else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+
+ }
- }// while
+ logger.info("[JuniperKeyBgpAdapter] Trying to connect");
- logger.error("[JuniperKeyBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ //if (passphrase == null || passphrase.equals("")) {
+ //manager.connect(username, keyUrl);
+ //} else {
+ //manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[JuniperKeyBgpAdapter] Login");
- }// getCommand
+ } catch (Exception e) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ logger.error("[JuniperKeyBgpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
+ }
- logger.debug("[JuniperKeyBgpAdapter] executeCommand called");
+ }// connect
- if (manager != null) {
+ // ---------------------- field methods
+ public int getPort() {
- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ return port;
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }
- }// if
+ public void setPort(int port) {
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ this.port = port;
- }// executeCommand
+ }
- public void connect() {
- }
+ public String getPrompt() {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ return prompt;
- logger.info("[JuniperKeyBgpAdapter] Connect called");
+ }
- try {
+ public void setPrompt(String prompt) {
- if (manager == null) {
+ this.prompt = prompt;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ public String getUrl() {
- }
+ return url;
- logger.info("[JuniperKeyBgpAdapter] Trying to
connect");
+ }
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[JuniperKeyBgpAdapter] Login");
+ public void setUrl(String url) {
- } catch (Exception e) {
+ this.url = url;
- logger
- .info("[JuniperKeyBgpAdapter] Error
occuring while connecting");
- // System.err.println("[JuniperKeyBgpAdapter] Error
occuring while
- // connecting");
- logger.info(e.getStackTrace().toString());
- // System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
- }
+ }
- }// connect
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- // ---------------------- field methods
+ logger.debug("[JuniperKeyBgpAdapter] Configuring available
operations ...");
- public int getPort() {
+ Iterator commands = null;
+ String token = null;
- return port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public void setPort(int port) {
+ token = (String) commands.next();
+ if (token.contains("BGP")) {
- this.port = port;
+ BgpCommand command = new BgpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public String getPrompt() {
+ }
- return prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public void setPrompt(String prompt) {
+ logger.error("[JUNIPERKEYBGPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- this.prompt = prompt;
+ }
- }
+ logger.debug("[JuniperKeyBgpAdapter] Available operations
configured");
- public String getUrl() {
+ }
- return url;
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, BgpCommandInterface bgpCommand)
{
- }
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- public void setUrl(String url) {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- this.url = url;
+ }
- }
+ while (temp.indexOf("---(more") > -1) {
- // ---------------------- Private methods
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ }
- logger
- .debug("[JuniperKeyBgpAdapter] Configuring
available operations ...");
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- try {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- token = tokenizer.nextToken();
- if (token.contains("BGP")) {
+ t2 = resultBuffer.toString();
- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- } catch (PerfSONARException e) {
+ return this.serviceEngineType;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- logger.debug("[JuniperKeyBgpAdapter] Available operations
configured");
+ logger.info("[JuniperKeyBgpAdapter] Webservice takeAction call
received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, BgpCommandInterface
bgpCommand) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("SUBJECTSTRING: " + subject);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- }
- while (temp.indexOf("---(more") > -1) {
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ //JuniperKeyBgpAdapter adapter = new JuniperKeyBgpAdapter();
- }
+ availableSpecificCommands = new ArrayList();
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ try {
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ } catch (NumberFormatException e1) {
- t2 = resultBuffer.toString();
+ logger.error("[JUNIPERKEYBGPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return t2.replace("" + prompt, "---END---");
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[JUNIPERKEYBGPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // ---------------------- Methods from service engine interface
+ }
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.debug("[JuniperKeyBgpAdapter] TelnetManager created: " + url
+ " " + port);
- return this.serviceEngineType;
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- }
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- logger
- .info("[JuniperKeyBgpAdapter] Webservice
takeAction call received");
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ bgpCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- JuniperKeyBgpAdapter adapter = new JuniperKeyBgpAdapter();
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();
- //adapter.connect(subject);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- availableSpecificCommands = new ArrayList();
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- username = properties.getProperty("service.r.mp." +
subject
- + ".username");
- keyUrl = properties.getProperty("service.r.mp." +
subject
- + ".keyUrl");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ }
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (temp.equalsIgnoreCase("")) {
- } catch (PerfSONARException e1) {
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ }
- }
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- logger.debug("[JuniperKeyBgpAdapter] TelnetManager created: "
+ url
- + " " + port);
+ } else if (bgpCommand.getMinParamCount() == 0) {
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- BgpCommandInterface bgpCommand =
this.getCommand(eventTypeString);
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- bgpCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- if (bgpCommand.getParameters().size() >= bgpCommand
- .getMinParamCount()
- && bgpCommand.getParameters().size()
<= bgpCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- } else if (bgpCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[JuniperKeyBgpAdapter] Command executed succesfully");
- }
+ Datum datum = new Datum();
- logger.info("[JuniperKeyBgpAdapter] Command executed
succesfully");
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Datum datum = new Datum();
+ logger.info("[JuniperKeyBgpAdapter] Constructing response message");
- if (valid)
- datum.setDatum(filterResult(temp, bgpCommand));
- else
- datum.setDatum(temp);
+ Message response = new Message();
- logger.info("[JuniperKeyBgpAdapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.info("[JuniperKeyBgpAdapter] takeAction finished");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ return response;
- logger.info("[JuniperKeyBgpAdapter] takeAction finished");
+ }
- return response;
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ JuniperKeyBgpAdapter adapter = new JuniperKeyBgpAdapter();
- // ---------------------- Stand-alond Test Method
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("junipernl");
- public static void main(String[] args) {
+ adapter.connect("junipernl");
- try {
- JuniperKeyBgpAdapter adapter = new
JuniperKeyBgpAdapter();
+ BgpCommandInterface bgpCommand;
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ try {
- adapter.connect("junipernl");
+ bgpCommand = adapter.getCommand("BGP_PEERING_STATUS");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- BgpCommandInterface bgpCommand;
+ //System.out.println(adapter.filterResult(temp, bgpCommand));
- try {
+ } catch (PerfSONARException e) {
- bgpCommand =
adapter.getCommand("BGP_PEERING_STATUS");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //e.printStackTrace();
- System.out.println(adapter.filterResult(temp,
bgpCommand));
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters;
@@ -8,8 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
-
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
import org.ggf.ns.nmwg.base.v2_0.EventType;
@@ -21,7 +19,6 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
@@ -29,7 +26,10 @@
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands.BgpCommandInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshManager;
@@ -44,607 +44,559 @@
*/
public class JuniperSshBgpAdapter implements BgpAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
- private String prompt = "";
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private int port = 0;
+ // ---------------------- constructors
+ public JuniperSshBgpAdapter() throws PerfSONARException {
- private String username = "";
+ try {
- private String password = "";
-
- private int caching = 0;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- // ---------------------- class-fields
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private List availableSpecificCommands = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private RemoteManager manager = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private LoggerComponent logger = null;
+ } catch (PerfSONARException e) {
- private PropertiesConfigurationComponent properties = null;
+ logger.error("[JUNIPERSSHBGPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperSshBgpAdapter] Constructor started");
- // ---------------------- constructors
+ logger.debug("[JuniperSshBgpAdapter] Constructor finished");
- public JuniperSshBgpAdapter() throws PerfSONARException {
+ }// JuniperSshBgpAdapter
- try {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.debug("[JuniperSshBgpAdapter] getAvailableSpecificCommands
called");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return availableSpecificCommands;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[JuniperSshBgpAdapter] setAvailableSpecificCommand
called");
- } catch (PerfSONARException e) {
+ this.availableSpecificCommands = availableSpecificCommands;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {
- }
+ logger.debug("[JuniperSshBgpAdapter] addAvailableSpecificCommand
called");
- logger.debug("[JuniperSshBgpAdapter] Constructor started");
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperSshBgpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// JuniperSshBgpAdapter
+ logger.debug("[JuniperSshBgpAdapter] getCommand called");
- // ---------------------- public methods
+ BgpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[JuniperSshBgpAdapter]
getAvailableSpecificCommands called");
+ command = (BgpCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[JuniperSshBgpAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[JuniperSshBgpAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperSshBgpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface executeCommand(BgpCommandInterface command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void addAvailableSpecificCommand(BgpCommandInterface command) {
+ logger.debug("[JuniperSshBgpAdapter] executeCommand called");
- logger.debug("[JuniperSshBgpAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- }// addAvailableSpecificCommand
+ }// if
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperSshBgpAdapter] executeCommand finished");
+ return command;
- logger.debug("[JuniperSshBgpAdapter] getCommand called");
+ }// executeCommand
+ public void connect() {
+ }
- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- while (it.hasNext()) {
+ logger.info("[JuniperSshBgpAdapter] Connect called");
- command = (BgpCommand) it.next();
+ try {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {
- logger.debug("[JuniperSshBgpAdapter] Command
found");
- return command;
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ //System.out.println(username);
+ //System.out.println(password);
- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- logger.error("[JuniperSshBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }
- }// getCommand
+ logger.info("[JuniperSshBgpAdapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[JuniperSshBgpAdapter] executeCommand called");
+ logger.info("[JuniperSshBgpAdapter Login");
- if (manager != null) {
+ } catch (Exception e) {
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[JuniperSshBgpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperSshBgpAdapter] executeCommand
finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[JuniperSshBgpAdapter] Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public String getPrompt() {
- //System.out.println(username);
- //System.out.println(password);
+ return prompt;
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ }
- }
+ public void setPrompt(String prompt) {
- logger.info("[JuniperSshBgpAdapter] Trying to
connect");
+ this.prompt = prompt;
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }
- logger.info("[JuniperSshBgpAdapter Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger.error("[JuniperSshBgpAdapter] Error occuring
while connecting");
- //System.err.println("[JuniperSshBgpAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[JuniperSshBgpAdapter] Configuring available
operations ...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("BGP")) {
- public String getPrompt() {
+ BgpCommand command = new BgpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHBGPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[JUNIPERSSHBGPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ logger.debug("[JuniperSshBgpAdapter] Available operations
configured");
- }
+ }
- public void setUrl(String url) {
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, BgpCommandInterface bgpCommand)
{
- this.url = url;
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- }
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- // ---------------------- Private methods
+ }
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ while (temp.indexOf("---(more") > -1) {
- logger.debug("[JuniperSshBgpAdapter] Configuring available
operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- StringTokenizer tokenizer = null;
- String token = null;
+ }
- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- token = tokenizer.nextToken();
- if (token.contains("BGP")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- } catch (PerfSONARException e) {
+ }
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- logger.debug("[JuniperSshBgpAdapter] Available operations
configured");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, BgpCommandInterface
bgpCommand) {
+ logger.info("[JuniperSshBgpAdapter] Webservice takeAction call
received");
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- while (temp.indexOf("---(more") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ //JuniperSshBgpAdapter adapter = new JuniperSshBgpAdapter();
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ // REPLACED
- StringBuffer resultBuffer = new StringBuffer(t2);
+ availableSpecificCommands = new ArrayList();
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ try {
- t2 = resultBuffer.toString();
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {
- }
+ logger.error("[JUNIPERSSHBGPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- // ---------------------- Methods from service engine interface
+ } catch (PerfSONARException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[JUNIPERSSHBGPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- return this.serviceEngineType;
+ }
- }
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- logger.info("[JuniperSshBgpAdapter] Webservice takeAction
call received");
+ //
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ bgpCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- JuniperSshBgpAdapter adapter = new JuniperSshBgpAdapter();
- //adapter.connect(subject);
+ }
- // REPLACED
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {
- availableSpecificCommands = new ArrayList();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- try {
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- } catch (NumberFormatException e1) {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ }
- }
+ if (temp.equalsIgnoreCase("")) {
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
+ }
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- //
+ } else if (bgpCommand.getMinParamCount() == 0) {
- BgpCommandInterface bgpCommand =
this.getCommand(eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- bgpCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- if (bgpCommand.getParameters().size() >= bgpCommand
- .getMinParamCount()
- && bgpCommand.getParameters().size()
<= bgpCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (bgpCommand.getMinParamCount() == 0) {
+ this.connect(subject);
+ temp = this.executeCommand(bgpCommand).getResult();
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- BgpCommandInterface cachedCommand =
(BgpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ } else {
- } else {
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ logger.info("[JuniperSshBgpAdapter] Command executed succesfully");
- logger.info("[JuniperSshBgpAdapter] Command executed
succesfully");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, bgpCommand));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperSshBgpAdapter] Constructing response message");
- logger.info("[JuniperSshBgpAdapter] Constructing response
message");
+ Message response = new Message();
- Message response = new Message();
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[JuniperSshBgpAdapter] takeAction finished");
- logger.info("[JuniperSshBgpAdapter] takeAction finished");
+ return response;
- return response;
+ }
- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // ---------------------- Stand-alond Test Method
+ try {
+ JuniperSshBgpAdapter adapter = new JuniperSshBgpAdapter();
- public static void main(String[] args) {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("juniper2");
- try {
- JuniperSshBgpAdapter adapter = new
JuniperSshBgpAdapter();
+ adapter.connect("juniper2");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("juniper2");
+ BgpCommandInterface bgpCommand;
- adapter.connect("juniper2");
+ try {
- BgpCommandInterface bgpCommand;
+ bgpCommand = adapter.getCommand("BGP");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- try {
+ } catch (PerfSONARException e) {
- bgpCommand = adapter.getCommand("BGP");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ //e.printStackTrace();
- } catch (PerfSONARException e) {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.2
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands;
@@ -19,195 +19,189 @@
*
*/
public class BgpCommand implements BgpCommandInterface {
-
- // ---------------------- class-fields
-
- private String deviceName = null;
- private String description = null;
- private String command = null;
- private String result = null;
- private List parameters = null;
-
- private int minParamCount = 0;
- private int maxParamCount = 0;
-
- private long timestamp = 0;
-
- // ---------------------- constructors
-
- public BgpCommand(String description, String command) {
-
- this.description = description;
- this.command = command;
- parameters = new ArrayList();
-
- }
- // ---------------------- public methods
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getCommand()
- */
- public String getCommand() {
-
- return command;
-
- }
+ // ---------------------- class-fields
+ private String deviceName = null;
+ private String description = null;
+ private String command = null;
+ private String result = null;
+ private List parameters = null;
+ private int minParamCount = 0;
+ private int maxParamCount = 0;
+ private long timestamp = 0;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getDescription()
- */
- public String getDescription() {
-
- return description;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getResult()
- */
- public String getResult() {
-
- return result;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getFilteredResult()
- */
- public String getFilteredResult() {
-
- return getResult();
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getFilteredResult()
- */
- public List getRecordsResult() {
-
- return null;
-
- }
+ // ---------------------- constructors
+ public BgpCommand(String description, String command) {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getParameters()
- */
- public List getParameters() {
-
- return parameters;
-
- }
+ this.description = description;
+ this.command = command;
+ parameters = new ArrayList();
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getParameterString()
- */
- public String getParameterString() {
-
- String parameterString = "";
- Iterator it = parameters.iterator();
-
- while (it.hasNext()) {
- parameterString += it.next()+" ";
- }
-
- parameterString.replace("\n", "----");
-
- return parameterString;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#setCommand(java.lang.String)
- */
- public void setCommand(String command) {
-
- this.command = command;
-
- }
+ // ---------------------- public methods
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getCommand()
+ */
+ public String getCommand() {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.Bgp.commands.BgpCommandInterface#setDescription(java.lang.String)
- */
- public void setDescription(String description) {
-
- this.description = description;
-
- }
+ return command;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#setResult(java.lang.String)
- */
- public void setResult(String result) {
-
- this.result = result;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#setParameters(java.util.List)
- */
- public void setParameters(List parameters) {
-
- this.parameters = parameters;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#addParameter(java.lang.String)
- */
- public void addParameter(String parameter) {
-
- parameters.add(parameter);
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getDescription()
+ */
+ public String getDescription() {
- public int getMinParamCount() {
-
- return minParamCount;
-
- }
+ return description;
- public int getMaxParamCount() {
+ }
- return maxParamCount;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getResult()
+ */
+ public String getResult() {
- public void setMinParamCount(int count) {
+ return result;
- minParamCount = count;
-
- }
+ }
- public void setMaxParamCount(int count) {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getFilteredResult()
+ */
+ public String getFilteredResult() {
- maxParamCount = count;
-
- }
+ return getResult();
- public String getDeviceName() {
+ }
- return deviceName;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getFilteredResult()
+ */
+ public List getRecordsResult() {
- public long getTimestamp() {
+ return null;
- return timestamp;
-
- }
+ }
- public void setDeviceName(String deviceName) {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getParameters()
+ */
+ public List getParameters() {
- this.deviceName = deviceName;
-
- }
+ return parameters;
- public void setTimestamp(long timestamp) {
+ }
- this.timestamp = timestamp;
-
- }
-
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#getParameterString()
+ */
+ public String getParameterString() {
+
+ String parameterString = "";
+ Iterator it = parameters.iterator();
+
+ while (it.hasNext()) {
+ parameterString += it.next() + " ";
+ }
+
+ parameterString.replace("\n", "----");
+
+ return parameterString;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#setCommand(java.lang.String)
+ */
+ public void setCommand(String command) {
+
+ this.command = command;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.Bgp.commands.BgpCommandInterface#setDescription(java.lang.String)
+ */
+ public void setDescription(String description) {
+
+ this.description = description;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#setResult(java.lang.String)
+ */
+ public void setResult(String result) {
+
+ this.result = result;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#setParameters(java.util.List)
+ */
+ public void setParameters(List parameters) {
+
+ this.parameters = parameters;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.bgp.commands.BgpCommandInterface#addParameter(java.lang.String)
+ */
+ public void addParameter(String parameter) {
+
+ parameters.add(parameter);
+
+ }
+
+ public int getMinParamCount() {
+
+ return minParamCount;
+
+ }
+
+ public int getMaxParamCount() {
+
+ return maxParamCount;
+
+ }
+
+ public void setMinParamCount(int count) {
+
+ minParamCount = count;
+
+ }
+
+ public void setMaxParamCount(int count) {
+
+ maxParamCount = count;
+
+ }
+
+ public String getDeviceName() {
+
+ return deviceName;
+
+ }
+
+ public long getTimestamp() {
+
+ return timestamp;
+
+ }
+
+ public void setDeviceName(String deviceName) {
+
+ this.deviceName = deviceName;
+
+ }
+
+ public void setTimestamp(long timestamp) {
+
+ this.timestamp = timestamp;
+
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.2
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.bgp.commands;
@@ -19,50 +19,49 @@
*/
public interface BgpCommandInterface extends CommandInterface {
- public abstract String getDeviceName();
-
- public abstract String getCommand();
+ public abstract String getDeviceName();
- public abstract String getDescription();
+ public abstract String getCommand();
- public abstract String getResult();
+ public abstract String getDescription();
- public abstract String getFilteredResult();
-
- public abstract List getRecordsResult();
+ public abstract String getResult();
- public abstract List getParameters();
-
- public abstract String getParameterString();
-
- public abstract int getMinParamCount();
-
- public abstract int getMaxParamCount();
-
- public abstract long getTimestamp();
+ public abstract String getFilteredResult();
- /**
- * Returns a enumeration of the paramteres, converted into a space
- * seperated string.
- *
- * @return String with space seperated String
- */
- public abstract void setDeviceName(String deviceName);
+ public abstract List getRecordsResult();
- public abstract void setCommand(String command);
+ public abstract List getParameters();
- public abstract void setDescription(String description);
+ public abstract String getParameterString();
- public abstract void setResult(String result);
+ public abstract int getMinParamCount();
- public abstract void setParameters(List parameters);
+ public abstract int getMaxParamCount();
- public abstract void addParameter(String parameter);
-
- public abstract void setMinParamCount(int count);
-
- public abstract void setMaxParamCount(int count);
-
- public abstract void setTimestamp(long timestamp);
+ public abstract long getTimestamp();
-}
\ No newline at end of file
+ /**
+ * Returns a enumeration of the paramteres, converted into a space
+ * seperated string.
+ *
+ * @return String with space seperated String
+ */
+ public abstract void setDeviceName(String deviceName);
+
+ public abstract void setCommand(String command);
+
+ public abstract void setDescription(String description);
+
+ public abstract void setResult(String result);
+
+ public abstract void setParameters(List parameters);
+
+ public abstract void addParameter(String parameter);
+
+ public abstract void setMinParamCount(int count);
+
+ public abstract void setMaxParamCount(int count);
+
+ public abstract void setTimestamp(long timestamp);
+}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,15 +1,13 @@
+/*
+ * Created on Jan 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSONAR
+ */
package org.perfsonar.service.measurementPoint.lookingGlassType.encryption;
-import java.io.ByteArrayOutputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
-import java.util.Enumeration;
-import java.util.Properties;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
@@ -21,143 +19,135 @@
import org.apache.ws.security.util.Base64;
-public class PasswordEncryptor {
- public static String encryptPassword (String pass) {
- String result = "";
+/**
+ * Class for encrypting and decrypting plain-text password fields in the
+ * metadataconfiguration-file.
+ *
+ * @author smelis
+ */
+public class PasswordEncryptor {
+
- // Encrypt the cleartext
- byte[] ciphertext;
+ /**
+ * Encrypting the supplied parameter
+ *
+ * @param pass
+ * @return String encryptedPassword
+ */
- try {
- // Create an array to hold the key
- byte[] encryptKey = "This is a test DESede
key".getBytes();
+ public static String encryptPassword(String pass) {
+
+ String result = "";
- // Create a DESede key spec from the key
- DESKeySpec spec = new DESKeySpec(encryptKey);
+ // Encrypt the cleartext
+ byte[] ciphertext;
- SecretKeyFactory keyfact =
SecretKeyFactory.getInstance("DES");
+ try {
+ // Create an array to hold the key
+ byte[] encryptKey = "This is a test DESede key".getBytes();
- SecretKey desKey = keyfact.generateSecret(spec);
+ // Create a DESede key spec from the key
+ DESKeySpec spec = new DESKeySpec(encryptKey);
- Cipher desCipher;
+ SecretKeyFactory keyfact = SecretKeyFactory.getInstance("DES");
- // Create the cipher
- desCipher = Cipher.getInstance("DES");
+ SecretKey desKey = keyfact.generateSecret(spec);
- // Initialize the cipher for encryption
- desCipher.init(Cipher.ENCRYPT_MODE, desKey);
+ Cipher desCipher;
- // Our cleartext
- byte[] cleartext = pass.getBytes("ISO-8859-1");
-
- ciphertext = desCipher.doFinal(cleartext);
+ // Create the cipher
+ desCipher = Cipher.getInstance("DES");
- return Base64.encode(ciphertext);
+ // Initialize the cipher for encryption
+ desCipher.init(Cipher.ENCRYPT_MODE, desKey);
- //System.out.println("result.length()" +
result.length());
- } catch (InvalidKeyException e) {
- e.printStackTrace();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- } catch (InvalidKeySpecException e) {
- e.printStackTrace();
- } catch (NoSuchPaddingException e) {
- e.printStackTrace();
- } catch (IllegalBlockSizeException e) {
- e.printStackTrace();
- } catch (BadPaddingException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
+ // Our cleartext
+ byte[] cleartext = pass.getBytes("ISO-8859-1");
+ ciphertext = desCipher.doFinal(cleartext);
- public static String decryptPassword (String pass) {
- String result = "";
+ return Base64.encode(ciphertext);
- try {
- // Create an array to hold the key
- byte[] encryptKey = "This is a test DESede
key".getBytes();
+ //System.out.println("result.length()" + result.length());
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (InvalidKeySpecException e) {
+ e.printStackTrace();
+ } catch (NoSuchPaddingException e) {
+ e.printStackTrace();
+ } catch (IllegalBlockSizeException e) {
+ e.printStackTrace();
+ } catch (BadPaddingException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
- // Create a DESede key spec from the key
- DESKeySpec spec = new DESKeySpec(encryptKey);
+
+ /**
+ * Decrypting the supplied parameter into a plain-text version
+ *
+ * @param pass
+ * @return String plain-text password
+ */
- SecretKeyFactory keyfact =
SecretKeyFactory.getInstance("DES");
+ public static String decryptPassword(String pass) {
+ String result = "";
- SecretKey desKey = keyfact.generateSecret(spec);
+ try {
+ // Create an array to hold the key
+ byte[] encryptKey = "This is a test DESede key".getBytes();
- Cipher desCipher;
+ // Create a DESede key spec from the key
+ DESKeySpec spec = new DESKeySpec(encryptKey);
- // Create the cipher
- desCipher = Cipher.getInstance("DES");
+ SecretKeyFactory keyfact = SecretKeyFactory.getInstance("DES");
- // Initialize the same cipher for decryption
- desCipher.init(Cipher.DECRYPT_MODE, desKey);
+ SecretKey desKey = keyfact.generateSecret(spec);
- //byte[] encrypted = pass.getBytes("ISO-8859-1");
- byte[] encrypted = Base64.decode(pass);
-
- //System.out.println("lengte van het te decrypteren
gedoe: " + encrypted.length);
- //for (int i = 0; i < encrypted.length; i++)
- // System.out.println("encrypted[" + i + "]: " +
(char) encrypted[i] + " (numeriek: "+ encrypted[i] + ")");
+ Cipher desCipher;
- // Decrypt the ciphertext
- byte[] cleartext1 = desCipher.doFinal(encrypted);
+ // Create the cipher
+ desCipher = Cipher.getInstance("DES");
- result = new String(cleartext1, "ISO-8859-1");
- } catch (InvalidKeyException e) {
- e.printStackTrace();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- } catch (InvalidKeySpecException e) {
- e.printStackTrace();
- } catch (NoSuchPaddingException e) {
- e.printStackTrace();
- } catch (IllegalBlockSizeException e) {
- e.printStackTrace();
- } catch (BadPaddingException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
+ // Initialize the same cipher for decryption
+ desCipher.init(Cipher.DECRYPT_MODE, desKey);
- return result;
- }
+ //byte[] encrypted = pass.getBytes("ISO-8859-1");
+ byte[] encrypted = Base64.decode(pass);
- public static void main (String[] args) {
- Properties pr = new Properties();
- String encrypted = encryptPassword("thisisasmalltest");
- pr.setProperty("password", encrypted);
+ //System.out.println("lengte van het te decrypteren gedoe: " +
encrypted.length);
+ //for (int i = 0; i < encrypted.length; i++)
+ // System.out.println("encrypted[" + i + "]: " + (char)
encrypted[i] + " (numeriek: "+ encrypted[i] + ")");
- try {
- pr.store(new FileOutputStream("test.properties"), "");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ // Decrypt the ciphertext
+ byte[] cleartext1 = desCipher.doFinal(encrypted);
-
- pr = new Properties();
- try {
- pr.setProperty("test", "testje");
- pr.load(new FileInputStream("test.properties"));
- pr.setProperty("test2", "testje");
- pr.store(new FileOutputStream("test.properties"), "");
+ result = new String(cleartext1, "ISO-8859-1");
+ } catch (InvalidKeyException e) {
+ e.printStackTrace();
+ } catch (NoSuchAlgorithmException e) {
+ e.printStackTrace();
+ } catch (InvalidKeySpecException e) {
+ e.printStackTrace();
+ } catch (NoSuchPaddingException e) {
+ e.printStackTrace();
+ } catch (IllegalBlockSizeException e) {
+ e.printStackTrace();
+ } catch (BadPaddingException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
- pr.load(new FileInputStream("test.properties"));
+ return result;
+ }
- pr.store(System.out, "");
- String decrypted =
decryptPassword(pr.getProperty("password"));
- System.out.println("decrypted password: " +
decrypted);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February, 7th 2007
- * Version Number: 0.5
+ * Created/Updated on January, 8th 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -22,13 +22,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters.CiscoBgpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters.CiscoIpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters.CiscoIpv6Adapter;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters.CiscoStatusAdapter;
/**
@@ -42,170 +43,160 @@
*/
public class CiscoAdapter implements ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- class-fields
+ // ---------------------- class-fields
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ private CiscoIpAdapter ciscoIpAdapter = null;
+ private CiscoIpv6Adapter ciscoIpv6Adapter = null;
+ private CiscoStatusAdapter ciscoStatusAdapter = null;
+ private CiscoBgpAdapter ciscoBgpAdapter = null;
- private LoggerComponent logger = null;
+ // ---------------------- constructors
+ public CiscoAdapter() throws PerfSONARException {
- private PropertiesConfigurationComponent properties = null;
+ try {
- private CiscoIpAdapter ciscoIpAdapter = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private CiscoIpv6Adapter ciscoIpv6Adapter = null;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private CiscoStatusAdapter ciscoStatusAdapter = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private CiscoBgpAdapter ciscoBgpAdapter = null;
+ ciscoIpAdapter = new CiscoIpAdapter();
+ ciscoIpv6Adapter = new CiscoIpv6Adapter();
+ ciscoStatusAdapter = new CiscoStatusAdapter();
+ ciscoBgpAdapter = new CiscoBgpAdapter();
- // ---------------------- constructors
+ } catch (PerfSONARException e) {
- public CiscoAdapter() throws PerfSONARException {
+ logger.error("[CISCOADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
+ }
- try {
+ }//CiscoAdapter
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return this.serviceEngineType;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }
- ciscoIpAdapter = new CiscoIpAdapter();
- ciscoIpv6Adapter = new CiscoIpv6Adapter();
- ciscoStatusAdapter = new CiscoStatusAdapter();
- ciscoBgpAdapter = new CiscoBgpAdapter();
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- } catch (PerfSONARException e) {
+ logger.info("[CiscoAdapter] Webservice takeAction call received");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject subject = metadata[0].getSubject();
+ EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
+ String subjectString = endpoint.getValue();
- }//CiscoAdapter
+ logger.debug("SUBJECTSTRING: " + subjectString);
- // ---------------------- Methods from service engine interface
+ EventType eventType = null;
+ String eventTypeString = "";
+ try {
+ eventType = metadata[0].getEventType();
+ eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (Exception e) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.command",
+ "No Command/EventType specified in request");
+ }
- return this.serviceEngineType;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ long last = 0;
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ String rate;
+ try {
+ rate = properties.getProperty(subjectString, "rate");
+ } catch (PerfSONARException e2) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e2.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
+ }
+ long rateLong = Long.parseLong(rate);
- logger.info("[CiscoAdapter] Webservice takeAction call
received");
+ try {
+ FileInputStream in = new FileInputStream("token_" +
subjectString);
+ ObjectInputStream is = new ObjectInputStream(in);
+ last = is.readLong();
+ is.close();
- Metadata[] metadata = request.getMetadataArray();
- Subject subject = metadata[0].getSubject();
- EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
- String subjectString = endpoint.getValue();
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e) {
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ try {
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e1) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Unable to write/retrieve token for request");
+ } catch (IOException e1) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Unable to write/retrieve token for request");
+ }
- EventType eventType = null;
- String eventTypeString = "";
- try {
- eventType = metadata[0].getEventType();
- eventTypeString = eventType.getEventType();
- } catch (Exception e) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.command",
- "No Command/EventType specified in
request");
- }
+ //e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ }
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (System.currentTimeMillis() - last > rateLong) {
- long last = 0;
+ if (eventTypeString.contains("IP_")) {
- String rate;
- try {
- rate = properties.getProperty("service.r.mp." +
subjectString
- + ".rate");
- } catch (PerfSONARException e2) {
- e2.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
- long rateLong = Long.parseLong(rate);
+ return this.ciscoIpAdapter.takeAction(actionType, request);
- try {
- FileInputStream in = new FileInputStream("token_" +
subjectString);
- ObjectInputStream is = new ObjectInputStream(in);
- last = is.readLong();
- is.close();
+ } else if (eventTypeString.contains("IPv6")) {
- FileOutputStream out = new FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e) {
+ return this.ciscoIpv6Adapter.takeAction(actionType, request);
- try {
- FileOutputStream out = new
FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new
ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Unable to write/retrieve
token for request");
- } catch (IOException e1) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Unable to write/retrieve
token for request");
- }
+ } else if (eventTypeString.contains("STATUS_")) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ return this.ciscoStatusAdapter.takeAction(actionType,
request);
- if (System.currentTimeMillis() - last > rateLong) {
+ } else if (eventTypeString.contains("BGP")) {
- if (eventTypeString.contains("IP_")) {
+ return this.ciscoBgpAdapter.takeAction(actionType, request);
- return
this.ciscoIpAdapter.takeAction(actionType, request);
+ } else {
- } else if (eventTypeString.contains("IPv6")) {
+ throw new PerfSONARException("error.mp.sshtelnet.request",
+ "[CiscoAdapter] Request not supported by this
device");
- return
this.ciscoIpv6Adapter.takeAction(actionType, request);
+ }
- } else if (eventTypeString.contains("STATUS_")) {
+ } else {
- return
this.ciscoStatusAdapter.takeAction(actionType, request);
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Too many requests");
- } else if (eventTypeString.contains("BGP")) {
+ }
- return
this.ciscoBgpAdapter.takeAction(actionType, request);
-
- } else {
-
- throw new
PerfSONARException("error.mp.sshtelnet.request",
- "[CiscoAdapter] Request not
supported by this device");
-
- }
-
- } else {
-
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Too many requests");
-
- }
-
- }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February 7th, 2007
- * Version Number: 0.2
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -22,13 +22,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters.CiscoKeyBgpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters.CiscoKeyIpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters.CiscoKeyIpv6Adapter;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters.CiscoKeyStatusAdapter;
/**
@@ -42,172 +43,161 @@
*/
public class CiscoKeyAdapter implements ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- class-fields
+ // ---------------------- class-fields
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ private CiscoKeyIpAdapter ciscoKeyIpAdapter = null;
+ private CiscoKeyIpv6Adapter ciscoKeyIpv6Adapter = null;
+ private CiscoKeyStatusAdapter ciscoKeyStatusAdapter = null;
+ private CiscoKeyBgpAdapter ciscoKeyBgpAdapter = null;
- private LoggerComponent logger = null;
+ // ---------------------- constructors
+ public CiscoKeyAdapter() throws PerfSONARException {
- private PropertiesConfigurationComponent properties = null;
+ try {
- private CiscoKeyIpAdapter ciscoKeyIpAdapter = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private CiscoKeyIpv6Adapter ciscoKeyIpv6Adapter = null;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private CiscoKeyStatusAdapter ciscoKeyStatusAdapter = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private CiscoKeyBgpAdapter ciscoKeyBgpAdapter = null;
+ ciscoKeyIpAdapter = new CiscoKeyIpAdapter();
+ ciscoKeyIpv6Adapter = new CiscoKeyIpv6Adapter();
+ ciscoKeyStatusAdapter = new CiscoKeyStatusAdapter();
+ ciscoKeyBgpAdapter = new CiscoKeyBgpAdapter();
- // ---------------------- constructors
+ } catch (PerfSONARException e) {
- public CiscoKeyAdapter() throws PerfSONARException {
+ logger.error("[CISCOKEYADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
+ }
- try {
+ }//JuniperAdapter
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return this.serviceEngineType;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }
- ciscoKeyIpAdapter = new CiscoKeyIpAdapter();
- ciscoKeyIpv6Adapter = new CiscoKeyIpv6Adapter();
- ciscoKeyStatusAdapter = new CiscoKeyStatusAdapter();
- ciscoKeyBgpAdapter = new CiscoKeyBgpAdapter();
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- } catch (PerfSONARException e) {
+ logger.info("[JuniperAdapter] Webservice takeAction call received");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject subject = metadata[0].getSubject();
+ EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
+ String subjectString = endpoint.getValue();
- }//JuniperAdapter
+ logger.debug("SUBJECTSTRING: " + subjectString);
- // ---------------------- Methods from service engine interface
+ EventType eventType = null;
+ String eventTypeString = "";
+ try {
+ eventType = metadata[0].getEventType();
+ eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (Exception e) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.command",
+ "No Command/EventType specified in request");
+ }
- return this.serviceEngineType;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
+ long last = 0;
- }
+ String rate;
+ try {
+ rate = properties.getProperty(subjectString, "rate");
+ } catch (PerfSONARException e2) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e2.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
+ }
+ long rateLong = Long.parseLong(rate);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ try {
+ FileInputStream in = new FileInputStream("token_" +
subjectString);
+ ObjectInputStream is = new ObjectInputStream(in);
+ last = is.readLong();
+ is.close();
- logger.info("[JuniperAdapter] Webservice takeAction call
received");
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e) {
- Metadata[] metadata = request.getMetadataArray();
- Subject subject = metadata[0].getSubject();
- EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
- String subjectString = endpoint.getValue();
+ try {
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e1) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Unable to write/retrieve token for request");
+ } catch (IOException e1) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Unable to write/retrieve token for request");
+ }
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ //e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ }
- EventType eventType = null;
- String eventTypeString = "";
- try {
- eventType = metadata[0].getEventType();
- eventTypeString = eventType.getEventType();
- } catch (Exception e) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.command",
- "No Command/EventType specified in
request");
- }
+ if (System.currentTimeMillis() - last > rateLong) {
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
- long last = 0;
+ if (eventTypeString.contains("IP_")) {
- String rate;
- try {
- rate = properties.getProperty("service.r.mp." +
subjectString
- + ".rate");
- } catch (PerfSONARException e2) {
- e2.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
- long rateLong = Long.parseLong(rate);
+ return this.ciscoKeyIpAdapter.takeAction(actionType,
request);
- try {
- FileInputStream in = new FileInputStream("token_" +
subjectString);
- ObjectInputStream is = new ObjectInputStream(in);
- last = is.readLong();
- is.close();
+ } else if (eventTypeString.contains("IPv6")) {
- FileOutputStream out = new FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e) {
+ return this.ciscoKeyIpv6Adapter.takeAction(actionType,
+ request);
- try {
- FileOutputStream out = new
FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new
ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Unable to write/retrieve
token for request");
- } catch (IOException e1) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Unable to write/retrieve
token for request");
- }
+ } else if (eventTypeString.contains("STATUS_")) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ return this.ciscoKeyStatusAdapter.takeAction(actionType,
+ request);
- if (System.currentTimeMillis() - last > rateLong) {
+ } else if (eventTypeString.contains("BGP")) {
- if (eventTypeString.contains("IP_")) {
+ return this.ciscoKeyBgpAdapter.takeAction(actionType,
request);
- return
this.ciscoKeyIpAdapter.takeAction(actionType, request);
+ } else {
- } else if (eventTypeString.contains("IPv6")) {
+ throw new PerfSONARException("error.mp.sshtelnet.request",
+ "[JuniperKeyAdapter] Request not supported by this
device");
- return
this.ciscoKeyIpv6Adapter.takeAction(actionType,
- request);
+ }
- } else if (eventTypeString.contains("STATUS_")) {
+ } else {
- return
this.ciscoKeyStatusAdapter.takeAction(actionType,
- request);
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Too many requests");
- } else if (eventTypeString.contains("BGP")) {
+ }
- return this.ciscoKeyBgpAdapter
- .takeAction(actionType,
request);
-
- } else {
-
- throw new
PerfSONARException("error.mp.sshtelnet.request",
- "[JuniperKeyAdapter] Request
not supported by this device");
-
- }
-
- } else {
-
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Too many requests");
-
- }
-
- }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February 7th, 2007
- * Version Number: 0.1
+ * Created/Updated on Janaury 8th, 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -12,9 +12,17 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Provider.Service;
+import java.util.Iterator;
+import java.util.Set;
+import javax.swing.SwingUtilities;
+
import org.ggf.ns.nmwg.base.v2_0.EventType;
import org.ggf.ns.nmwg.base.v2_0.Message;
import org.ggf.ns.nmwg.base.v2_0.Metadata;
@@ -22,15 +30,18 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters.CiscoSshBgpAdapter;
+
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters.CiscoSshIpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters.CiscoSshIpv6Adapter;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters.CiscoSshStatusAdapter;
+
/**
* Implementation class that supports querying the device (Juniper) for
* ip information
@@ -51,7 +62,7 @@
private LoggerComponent logger = null;
- private PropertiesConfigurationComponent properties = null;
+ private MetadataConfiguration properties = null;
private CiscoSshIpAdapter ciscoSshIpAdapter = null;
@@ -70,8 +81,8 @@
logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
.getComponent(ComponentNames.LOGGER);
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
@@ -82,7 +93,7 @@
} catch (PerfSONARException e) {
- e.printStackTrace();
+
logger.error("[CISCOSSHADAPTER][Constructor]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
}
@@ -100,6 +111,7 @@
}
+
/**
* @see ServiceEngine.java
*/
@@ -113,29 +125,30 @@
EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
String subjectString = endpoint.getValue();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subjectString);
EventType eventType = null;
String eventTypeString = "";
try {
eventType = metadata[0].getEventType();
eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
+
} catch (Exception e) {
- e.printStackTrace();
+
logger.error("[CISCOSSHADAPTER][TakeAcion]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.command",
"No Command/EventType specified in
request");
}
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
long last = 0;
String rate;
try {
- rate = properties.getProperty("service.r.mp." +
subjectString
- + ".rate");
+ rate = properties.getProperty(subjectString, "rate");
} catch (PerfSONARException e2) {
- e2.printStackTrace();
+
logger.error("[CISCOSSHADAPTER][TakeAcion]"+e2.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
}
@@ -161,18 +174,18 @@
s.writeLong(System.currentTimeMillis());
s.flush();
} catch (FileNotFoundException e1) {
- e1.printStackTrace();
+
logger.error("[CISCOSSHADAPTER][TakeAcion]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.token",
"Unable to write/retrieve
token for request");
} catch (IOException e1) {
- e1.printStackTrace();
+
logger.error("[CISCOSSHADAPTER][TakeAcion]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.token",
"Unable to write/retrieve
token for request");
}
- e.printStackTrace();
+ //e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
+
logger.error("[CISCOSSHADAPTER][TakeAcion]"+e.getStackTrace().toString());
}
if (System.currentTimeMillis() - last > rateLong) {
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February 7th, 2007
- * Version Number: 0.4
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -22,13 +22,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters.JuniperBgpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters.JuniperIpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters.JuniperIpv6Adapter;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters.JuniperStatusAdapter;
/**
@@ -42,171 +43,160 @@
*/
public class JuniperAdapter implements ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- class-fields
+ // ---------------------- class-fields
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ private JuniperIpAdapter juniperIpAdapter = null;
+ private JuniperIpv6Adapter juniperIpv6Adapter = null;
+ private JuniperStatusAdapter juniperStatusAdapter = null;
+ private JuniperBgpAdapter juniperBgpAdapter = null;
- private LoggerComponent logger = null;
+ // ---------------------- constructors
+ public JuniperAdapter() throws PerfSONARException {
- private PropertiesConfigurationComponent properties = null;
+ try {
- private JuniperIpAdapter juniperIpAdapter = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private JuniperIpv6Adapter juniperIpv6Adapter = null;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private JuniperStatusAdapter juniperStatusAdapter = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private JuniperBgpAdapter juniperBgpAdapter = null;
+ juniperIpAdapter = new JuniperIpAdapter();
+ juniperIpv6Adapter = new JuniperIpv6Adapter();
+ juniperStatusAdapter = new JuniperStatusAdapter();
+ juniperBgpAdapter = new JuniperBgpAdapter();
- // ---------------------- constructors
+ } catch (PerfSONARException e) {
- public JuniperAdapter() throws PerfSONARException {
+ logger.error("[JUNIPERADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
+ }
- try {
+ }//JuniperAdapter
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return this.serviceEngineType;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }
- juniperIpAdapter = new JuniperIpAdapter();
- juniperIpv6Adapter = new JuniperIpv6Adapter();
- juniperStatusAdapter = new JuniperStatusAdapter();
- juniperBgpAdapter = new JuniperBgpAdapter();
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- } catch (PerfSONARException e) {
+ logger.info("[JuniperAdapter] Webservice takeAction call received");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject subject = metadata[0].getSubject();
+ EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
+ String subjectString = endpoint.getValue();
- }//JuniperAdapter
+ logger.debug("SUBJECTSTRING: " + subjectString);
- // ---------------------- Methods from service engine interface
+ EventType eventType = null;
+ String eventTypeString = "";
+ try {
+ eventType = metadata[0].getEventType();
+ eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (Exception e) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.command",
+ "No Command/EventType specified in request");
+ }
- return this.serviceEngineType;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
+ long last = 0;
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ String rate;
+ try {
+ rate = properties.getProperty(subjectString, "rate");
+ } catch (PerfSONARException e2) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e2.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
+ }
+ long rateLong = Long.parseLong(rate);
- logger.info("[JuniperAdapter] Webservice takeAction call
received");
+ try {
+ FileInputStream in = new FileInputStream("token_" +
subjectString);
+ ObjectInputStream is = new ObjectInputStream(in);
+ last = is.readLong();
+ is.close();
- Metadata[] metadata = request.getMetadataArray();
- Subject subject = metadata[0].getSubject();
- EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
- String subjectString = endpoint.getValue();
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e) {
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ try {
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e1) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Unable to write/retrieve token for request");
+ } catch (IOException e1) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Unable to write/retrieve token for request");
+ }
- EventType eventType = null;
- String eventTypeString = "";
- try {
- eventType = metadata[0].getEventType();
- eventTypeString = eventType.getEventType();
- } catch (Exception e) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.command",
- "No Command/EventType specified in
request");
- }
+ //e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ }
+ if (System.currentTimeMillis() - last > rateLong) {
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
- long last = 0;
+ if (eventTypeString.contains("IP_")) {
- String rate;
- try {
- rate = properties.getProperty("service.r.mp." +
subjectString
- + ".rate");
- } catch (PerfSONARException e2) {
- e2.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
- long rateLong = Long.parseLong(rate);
+ return this.juniperIpAdapter.takeAction(actionType, request);
- try {
- FileInputStream in = new FileInputStream("token_" +
subjectString);
- ObjectInputStream is = new ObjectInputStream(in);
- last = is.readLong();
- is.close();
+ } else if (eventTypeString.contains("IPv6")) {
- FileOutputStream out = new FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e) {
+ return this.juniperIpv6Adapter.takeAction(actionType,
request);
- try {
- FileOutputStream out = new
FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new
ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e1) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Unable to write/retrieve
token for request");
- } catch (IOException e1) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Unable to write/retrieve
token for request");
- }
+ } else if (eventTypeString.contains("STATUS_")) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ return this.juniperStatusAdapter.takeAction(actionType,
request);
- if (System.currentTimeMillis() - last > rateLong) {
+ } else if (eventTypeString.contains("BGP")) {
- if (eventTypeString.contains("IP_")) {
+ return this.juniperBgpAdapter.takeAction(actionType,
request);
- return
this.juniperIpAdapter.takeAction(actionType, request);
+ } else {
- } else if (eventTypeString.contains("IPv6")) {
+ throw new PerfSONARException("error.mp.sshtelnet.request",
+ "[JuniperAdapter] Request not supported by this
device");
- return
this.juniperIpv6Adapter.takeAction(actionType, request);
+ }
- } else if (eventTypeString.contains("STATUS_")) {
+ } else {
- return this.juniperStatusAdapter
- .takeAction(actionType,
request);
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Too many requests");
- } else if (eventTypeString.contains("BGP")) {
+ }
- return
this.juniperBgpAdapter.takeAction(actionType, request);
-
- } else {
-
- throw new
PerfSONARException("error.mp.sshtelnet.request",
- "[JuniperAdapter] Request not
supported by this device");
-
- }
-
- } else {
-
- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Too many requests");
-
- }
-
- }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February, 7th 2007
- * Version Number: 0.4
+ * Created/Updated on January, 8th 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -22,13 +22,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters.JuniperKeyBgpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters.JuniperKeyIpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters.JuniperKeyIpv6Adapter;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters.JuniperKeyStatusAdapter;
/**
@@ -51,7 +52,7 @@
private LoggerComponent logger = null;
- private PropertiesConfigurationComponent properties = null;
+ private MetadataConfiguration properties = null;
private JuniperKeyIpAdapter juniperKeyIpAdapter = null;
@@ -70,8 +71,8 @@
logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
.getComponent(ComponentNames.LOGGER);
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
@@ -82,7 +83,7 @@
} catch (PerfSONARException e) {
- e.printStackTrace();
+
logger.error("[JUNIPERKEYADAPTER][Constructor]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
}
@@ -113,29 +114,30 @@
EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
String subjectString = endpoint.getValue();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subjectString);
EventType eventType = null;
String eventTypeString = "";
try {
eventType = metadata[0].getEventType();
eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
+
} catch (Exception e) {
- e.printStackTrace();
+
logger.error("[JUNIPERKEYADAPTER][TakeAction]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.command",
"No Command/EventType specified in
request");
}
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
long last = 0;
String rate;
try {
- rate = properties.getProperty("service.r.mp." +
subjectString
- + ".rate");
+ rate = properties.getProperty(subjectString, "rate");
} catch (PerfSONARException e2) {
- e2.printStackTrace();
+
logger.error("[JUNIPERKEYADAPTER][TakeAction]"+e2.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
}
@@ -161,18 +163,18 @@
s.writeLong(System.currentTimeMillis());
s.flush();
} catch (FileNotFoundException e1) {
- e1.printStackTrace();
+
logger.error("[JUNIPERKEYADAPTER][TakeAction]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.token",
"Unable to write/retrieve
token for request");
} catch (IOException e1) {
- e1.printStackTrace();
+
logger.error("[JUNIPERKEYADAPTER][TakeAction]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.token",
"Unable to write/retrieve
token for request");
}
- e.printStackTrace();
+ //e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
+
logger.error("[JUNIPERKEYADAPTER][TakeAction]"+e.getStackTrace().toString());
}
if (System.currentTimeMillis() - last > rateLong) {
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February 7th, 2007
- * Version Number: 0.2
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -22,13 +22,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.adapters.JuniperSshBgpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters.JuniperSshIpAdapter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters.JuniperSshIpv6Adapter;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters.JuniperSshStatusAdapter;
/**
@@ -51,7 +52,7 @@
private LoggerComponent logger = null;
- private PropertiesConfigurationComponent properties = null;
+ private MetadataConfiguration properties = null;
private JuniperSshIpAdapter juniperSshIpAdapter = null;
@@ -70,8 +71,8 @@
logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
.getComponent(ComponentNames.LOGGER);
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
@@ -82,7 +83,7 @@
} catch (PerfSONARException e) {
- e.printStackTrace();
+
logger.error("[JUNIPERSSHADAPTER][Constructor]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
}
@@ -113,29 +114,30 @@
EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
String subjectString = endpoint.getValue();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subjectString);
EventType eventType = null;
String eventTypeString = "";
try {
eventType = metadata[0].getEventType();
eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
+
} catch (Exception e) {
- e.printStackTrace();
+
logger.error("[JUNIPERSSHADAPTER][TakeAction]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.command",
"No Command/EventType specified in
request");
}
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
long last = 0;
String rate;
try {
- rate = properties.getProperty("service.r.mp." +
subjectString
- + ".rate");
+ rate = properties.getProperty(subjectString, "rate");
} catch (PerfSONARException e2) {
- e2.printStackTrace();
+
logger.error("[JUNIPERSSHADAPTER][TakeAction]"+e2.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
}
@@ -161,18 +163,18 @@
s.writeLong(System.currentTimeMillis());
s.flush();
} catch (FileNotFoundException e1) {
- e1.printStackTrace();
+
logger.error("[JUNIPERSSHADAPTER][TakeAction]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.token",
"Unable to write/retrieve
token for request");
} catch (IOException e1) {
- e1.printStackTrace();
+
logger.error("[JUNIPERSSHADAPTER][TakeAction]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.token",
"Unable to write/retrieve
token for request");
}
- e.printStackTrace();
+ //e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
+
logger.error("[JUNIPERSSHADAPTER][TakeAction]"+e.getStackTrace().toString());
}
if (System.currentTimeMillis() - last > rateLong) {
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,5 +1,23 @@
+/*
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSonar
+ *
+ * Stijn Verstichel
()
+ * Stijn Melis
()
+ */
package
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Provider.Service;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.swing.SwingUtilities;
+
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.EventType;
import org.ggf.ns.nmwg.base.v2_0.Message;
@@ -11,123 +29,144 @@
import org.perfsonar.service.base.engine.ServiceEngineFactory;
+/**
+ * Thread for executing the retrieval process of a command on a certain
+ * device
+ *
+ * @author svrstich
+ */
public class RequestExecutingThread extends Thread {
-
- private int id;
- private String serviceEngineString = null;
- private String actionType = null;
- private Message requestMessage = null;
- private Message resultMessage = null;
- private RequestMonitor requestMonitor = null;
-
- private Metadata requestMetadata = null;
-
- public RequestExecutingThread(int id,
- String actionType,
- String serviceEngineString,
- Message requestMessage,
- Metadata requestMetadata,
- RequestMonitor requestMonitor) {
+ // ---------------------------- class-fields
+ private int id;
+ private String serviceEngineString = null;
+ private String actionType = null;
+ private Message requestMessage = null;
+ private Message resultMessage = null;
+ private RequestMonitor requestMonitor = null;
+ private Metadata requestMetadata = null;
+ //private long timeout = 0;
- this.id = id;
-
- this.actionType = actionType;
- this.serviceEngineString = serviceEngineString;
- this.requestMessage = requestMessage;
- this.requestMonitor = requestMonitor;
+ public RequestExecutingThread(int id,
+ String actionType,
+ String serviceEngineString,
+ Message requestMessage,
+ Metadata requestMetadata,
+ RequestMonitor requestMonitor) {
- this.requestMetadata = requestMetadata;
-
- }
+ this.id = id;
- public void run() {
- try {
- ServiceEngine serviceEngine = ServiceEngineFactory
-
.getServiceEngine(serviceEngineString);
- resultMessage = serviceEngine.takeAction(actionType,
requestMessage);
+ this.actionType = actionType;
+ this.serviceEngineString = serviceEngineString;
+ this.requestMessage = requestMessage;
+ this.requestMonitor = requestMonitor;
- // Inclusion of the result code tags
- Metadata resultCodeMetadata = new Metadata();
- resultCodeMetadata.setId("resultCodeMeta_"
- + requestMetadata.getId());
+ this.requestMetadata = requestMetadata;
+ }
+
+ /*public RequestExecutingThread(int id,
+ String actionType,
+ String serviceEngineString,
+ Message requestMessage,
+ Metadata requestMetadata,
+ RequestMonitor requestMonitor,
+ long timeout) {
- Subject resultCodeSubject = new Subject();
- resultCodeSubject.setId("resultCodeSubj_"
- + requestMetadata.getId());
-
resultCodeSubject.setMetadataIdRef(requestMetadata.getId());
+ this.id = id;
- EventType resultCodeEventType = new EventType();
- resultCodeEventType.setId("resultCodeEventType_"
- + requestMetadata.getId());
-
resultCodeEventType.setEventType("success.mp.sshtelnet");
+ this.actionType = actionType;
+ this.serviceEngineString = serviceEngineString;
+ this.requestMessage = requestMessage;
+ this.requestMonitor = requestMonitor;
- resultCodeMetadata.addChild(resultCodeSubject);
- resultCodeMetadata.addChild(resultCodeEventType);
+ this.requestMetadata = requestMetadata;
- Data resultCodeData = new Data();
- resultCodeData
- .setId("resultCodeData_" +
requestMetadata.getId());
- resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + requestMetadata.getId());
+ this.timeout = timeout;
+ }*/
- Datum resultCodeDatum = new Datum();
- resultCodeDatum.setId("resultCodeDatum_"
- + requestMetadata.getId());
- resultCodeDatum.setValue("Successfully executed
request");
+ /**
+ * Retrieve the result and compose it into an XML compliant
+ * document
+ */
+ public void run() {
+ try {
+ //if (timeout > 0) //timeout <=0 -> no timeout
+ // requestMonitor.startTimer(this, timeout);
+
+ ServiceEngine serviceEngine =
ServiceEngineFactory.getServiceEngine(serviceEngineString);
+ resultMessage = serviceEngine.takeAction(actionType,
requestMessage);
+
+ // Inclusion of the result code tags
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
requestMetadata.getId());
- resultCodeData.addChild(resultCodeDatum);
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
requestMetadata.getId());
+ resultCodeSubject.setMetadataIdRef(requestMetadata.getId());
- resultMessage.setMetadata(resultCodeMetadata);
- resultMessage.setData(resultCodeData);
-
- } catch (PerfSONARException e) {
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
requestMetadata.getId());
+ resultCodeEventType.setEventType("success.mp.sshtelnet");
- resultMessage = new Message();
- resultMessage.setMetadata(requestMetadata);
- String metadataIdRef = requestMetadata.getId();
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);
- for (int j = 0; j <
requestMessage.getDataArray().length; j++)
- if
(requestMessage.getDataArray()[j].getMetadataIdRef().equalsIgnoreCase(
- metadataIdRef))
-
resultMessage.setData(requestMessage.getDataArray()[j]);
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" +
requestMetadata.getId());
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
requestMetadata.getId());
- Metadata resultCodeMetadata = new Metadata();
- resultCodeMetadata.setId("resultCodeMeta_"
- + requestMetadata.getId());
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" +
requestMetadata.getId());
+ resultCodeDatum.setValue("Successfully executed request");
- Subject resultCodeSubject = new Subject();
- resultCodeSubject.setId("resultCodeSubj_"
- + requestMetadata.getId());
-
resultCodeSubject.setMetadataIdRef(requestMetadata.getId());
+ resultCodeData.addChild(resultCodeDatum);
- EventType resultCodeEventType = new EventType();
- resultCodeEventType.setId("resultCodeEventType_"
- + requestMetadata.getId());
- resultCodeEventType.setEventType(e.getResultCode());
+ resultMessage.setMetadata(resultCodeMetadata);
+ resultMessage.setData(resultCodeData);
- resultCodeMetadata.addChild(resultCodeSubject);
- resultCodeMetadata.addChild(resultCodeEventType);
+ //Something went wrong during the retrieval process.
+ //Constructing the XML-compliant error message
+ } catch (PerfSONARException e) {
- Data resultCodeData = new Data();
- resultCodeData
- .setId("resultCodeData_" +
requestMetadata.getId());
- resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + requestMetadata.getId());
+ resultMessage = new Message();
+ resultMessage.setMetadata(requestMetadata);
+ String metadataIdRef = requestMetadata.getId();
- Datum resultCodeDatum = new Datum();
- resultCodeDatum.setId("resultCodeDatum_"
- + requestMetadata.getId());
- resultCodeDatum.setValue(e.getResultDescription());
+ for (int j = 0; j < requestMessage.getDataArray().length; j++) {
+ if
(requestMessage.getDataArray()[j].getMetadataIdRef().equalsIgnoreCase(
+ metadataIdRef)) {
+ resultMessage.setData(requestMessage.getDataArray()[j]);
+ }
+ }
- resultCodeData.addChild(resultCodeDatum);
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
requestMetadata.getId());
- resultMessage.setMetadata(resultCodeMetadata);
- resultMessage.setData(resultCodeData);
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
requestMetadata.getId());
+ resultCodeSubject.setMetadataIdRef(requestMetadata.getId());
- }
-
- requestMonitor.setCompleted(id, resultMessage);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
requestMetadata.getId());
+ resultCodeEventType.setEventType(e.getResultCode());
- }
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);
+
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" +
requestMetadata.getId());
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
requestMetadata.getId());
+
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" +
requestMetadata.getId());
+ resultCodeDatum.setValue(e.getResultDescription());
+
+ resultCodeData.addChild(resultCodeDatum);
+
+ resultMessage.setMetadata(resultCodeMetadata);
+ resultMessage.setData(resultCodeData);
+
+ }
+ requestMonitor.setCompleted(id, resultMessage);
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,54 +1,112 @@
+/*
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSonar
+ *
+ * Stijn Verstichel
()
+ * Stijn Melis
()
+ */
package
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters;
+import java.util.Timer;
+import java.util.TimerTask;
+
import org.ggf.ns.nmwg.base.v2_0.Message;
+/**
+ * Monitoring loop, keeping track of the progress of all individual
+ * RequestExecutingThread.
+ *
+ * @author svrstich
+ */
public class RequestMonitor {
-
- private int size;
- private boolean[] requestsCompletedTable = null;
- private Message[] resultMessagesTable = null;
-
- public RequestMonitor(int size) {
-
- this.size = size;
- requestsCompletedTable = new boolean[size];
- resultMessagesTable = new Message[size];
-
- for (int i = 0; i < requestsCompletedTable.length; i++) {
- requestsCompletedTable[i] = false;
- }
-
- }
- public int getSize() {
- return size;
- }
+ // ---------------------------- class-fields
+ private int size;
+ private boolean[] requestsCompletedTable = null;
+ private Message[] resultMessagesTable = null;
+
+ public RequestMonitor(int size) {
- public void setSize(int size) {
- this.size = size;
- }
-
- public synchronized void setCompleted(int id, Message resultMessage) {
-
- if (id < size) {
- requestsCompletedTable[id] = true;
- resultMessagesTable[id] = resultMessage;
- }
-
- }
-
- public synchronized boolean isCompleted() {
-
- for (int i = 0; i < requestsCompletedTable.length; i++) {
- if (!requestsCompletedTable[i])
- return false;
- }
- return true;
- }
-
- public Message[] getResultMessages() {
-
- return resultMessagesTable;
-
- }
+ this.size = size;
+ requestsCompletedTable = new boolean[size];
+ resultMessagesTable = new Message[size];
+
+ for (int i = 0; i < requestsCompletedTable.length; i++) {
+ requestsCompletedTable[i] = false;
+ }
+
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ /**
+ * Method to be called by the RequestExecutingThread upon completion
+ * in order to notify the Monitor that the retrieval process is
+ * finished
+ *
+ * @param id
+ * @param resultMessage
+ */
+ public synchronized void setCompleted(int id, Message resultMessage) {
+
+ if (id < size) {
+ requestsCompletedTable[id] = true;
+ resultMessagesTable[id] = resultMessage;
+ }
+
+ }
+
+ /**
+ * Checks all RequestExecutingThreads and returns true if and only if
+ * all threads have finished
+ *
+ * @return boolean
+ */
+ public synchronized boolean isCompleted() {
+
+ for (int i = 0; i < requestsCompletedTable.length; i++) {
+ if (!requestsCompletedTable[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Retrieves the table of all XML-compliant messages of the individual
+ * RequestIndividualThreads to be composed in a single response
+ * Message
+ *
+ * @return Message[]
+ */
+ public Message[] getResultMessages() {
+
+ return resultMessagesTable;
+
+ }
+
+ public void startTimer(RequestExecutingThread thread, long timeout) {
+ Timer timer = new Timer();
+ timer.schedule(new TimeoutTask(thread), timeout);
+ }
+
+ public class TimeoutTask extends TimerTask {
+
+ private RequestExecutingThread thread;
+
+ public TimeoutTask (RequestExecutingThread thread) {
+ this.thread = thread;
+ }
+
+ public void run () {
+ thread.interrupt();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,3 +1,11 @@
+/*
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSonar
+ *
+ * Stijn Verstichel
()
+ * Stijn Melis
()
+ */
package
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters;
import java.io.BufferedReader;
@@ -3,5 +11,4 @@
import java.io.DataOutputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -12,907 +19,1329 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
import java.util.StringTokenizer;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.IllegalAddException;
+import org.jdom.JDOMException;
+import org.jdom.Namespace;
+import org.jdom.input.SAXBuilder;
+import org.jdom.output.XMLOutputter;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+/**
+ * Class used to construct the service.properties file /
metadataconfiguration
+ * file
+ *
+ * @author svrstich
+ * @author smelis
+ */
public class ServicePropertiesConfigurator {
- String[] lines;
+ private static Namespace NMWG = Namespace.getNamespace("nmwg",
"http://ggf.org/ns/nmwg/base/2.0/");
- String previousDevices;
+ public static String EVENTTYPE_PREFIX =
"http://schemas.perfsonar.net/tools/sshtelnet/";
+ public static String EVENTTYPE_VERSION = "1.0";
+
+ String[] lines;
+ String previousDevices;
- private Properties prop;
-
- private static String MINIMUM_PACKAGE = "minimumpackage.txt";
+ //private Properties prop;
+ Document doc;
+ Element store;
+ Element metadata;
+ Element data;
+ private static String MINIMUM_PACKAGE = "minimumpackage.txt";
- public ServicePropertiesConfigurator() {
- lines = new String[3];
- prop = new Properties();
- }
+ public ServicePropertiesConfigurator() {
+ lines = new String[3];
+ //prop = new Properties();
+ }
- public void doStuff(String outputFile) {
+ public void doStuff(String outputFile) {
- try {
- BufferedReader br = new BufferedReader(new
InputStreamReader(
- System.in));
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));
- //BufferedWriter out = null;
- //out = new BufferedWriter(new FileWriter(outputFile,
true));
- //FileOutputStream out = new FileOutputStream
(outputFile, true);
-
- //List devices = new ArrayList();
+ doc = new Document();
+ store = new Element("store", NMWG);
- previousDevices = new String(); // devices defined
in given service.properties file
- //List types = new ArrayList();
- //List commands = new ArrayList();
+ previousDevices = new String(); // devices defined in given
service.properties file
- List previousCommands = new ArrayList(); // list of
commands for every device in given
- // service.properties (also in String format)
+ File outpFile = new File(outputFile);
- //List allCommands = new ArrayList();
+ /*if (outpFile.exists()) {
+ System.out.println("Loading existing properties...");
+ prop.load(new FileInputStream(outputFile));
+ System.out.println("Properties loaded");
+ }
+ System.out.println("Starting configuration...");
+ prop.setProperty("service.ls.registration_file", "");
+ */
+ System.out.println();
+
System.out.println("|---------------------------------------------|");
+ System.out.println("| Configuration of the devicesTelnet / SSH
MP |");
+
System.out.println("|---------------------------------------------|");
+ System.out.println();
- File outpFile = new File (outputFile);
-
- //System.out.println("outputFile object created");
-
- if (outpFile.exists()) {
- System.out.println("Loading existing
properties...");
- prop.load(new FileInputStream(outputFile));
- System.out.println("Properties loaded");
- }
- System.out.println("Starting configuration...");
- prop.setProperty("service.ls.registration_file", "");
+ System.out.println("Do you already have a manually edited
metadataConfiguration files available ? (yes/no)");
+ String previous = "";
+ previous = br.readLine();
+ while (!previous.equalsIgnoreCase("yes") &&
!previous.equalsIgnoreCase("no")) {
+ System.out.println("Please reply with yes/no!");
+ previous = br.readLine();
+ }
- System.out.println();
- System.out
-
.println("|---------------------------------------------|");
- System.out
- .println("| Configuration of the devicesTelnet / SSH
MP |");
- System.out
-
.println("|---------------------------------------------|");
- System.out.println();
+ if (previous.equalsIgnoreCase("yes")) { // manually edited
service.properties
+ try {
+ System.out.println();
+ System.out.println("Please enter the path to this
configuration file");
+ String file = br.readLine();
- System.out
- .println("Do you already have a manually edited
service.properties files available ? (yes/no)");
- String previous = "";
- previous = br.readLine();
- while (!previous.equalsIgnoreCase("yes")
- && !previous.equalsIgnoreCase("no")) {
- System.out.println("Please reply with
yes/no!");
- previous = br.readLine();
- }
+ SAXBuilder builder = new SAXBuilder();
+ doc = builder.build(file);
- if (previous.equalsIgnoreCase("yes")) { // manually
edited service.properties
- System.out.println();
- System.out
- .println("Please enter the path to this
configuration file");
- String file = br.readLine();
-
- prop.load(new FileInputStream(new
File(file)));
-
- } else { // answer == no
- System.out
- .println("Do you have a CSV file which
defines the configuration? (yes/no)");
- previous = br.readLine();
- while (!previous.equalsIgnoreCase("yes")
- &&
!previous.equalsIgnoreCase("no")) {
- System.out.println("Please reply with
yes/no !");
- previous = br.readLine();
- }
+ store = doc.getRootElement();
- if (previous.equalsIgnoreCase("yes")){ // csv
file containing the configuration
- System.out
- .println("Please enter the path to
this CSV file");
- previous = br.readLine();
- System.out.println("Parsing CSV
file...");
+ } catch (JDOMException e) {
+ System.out.println("[ERROR] entered configuration file
does not exist");
+ e.printStackTrace();
+ }
- parseCSVFile(previous, outputFile);
+ } else { // answer == no
+ System.out.println("Do you have a CSV file which defines the
configuration? (yes/no)");
+ previous = br.readLine();
+ while (!previous.equalsIgnoreCase("yes") &&
!previous.equalsIgnoreCase("no")) {
+ System.out.println("Please reply with yes/no !");
+ previous = br.readLine();
+ }
- System.out.println("Parsing done.");
+ if (previous.equalsIgnoreCase("yes")) { // csv file
containing the configuration
+ System.out.println("Please enter the path to this CSV
file");
+ previous = br.readLine();
+ System.out.println("Parsing CSV file...");
- } else { // answer == no
+ parseCSVFile(previous, outputFile);
- askManually(outputFile); // manually
provide configuration information
- }
- }
-
- prop.store(new FileOutputStream(outputFile),
"Service.properties");
-
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ System.out.println("Parsing done.");
- private void parseCSVFile(String file, String outputFile) {
- try {
- // Read all lines from txt file
- lines = readLinesFromFile(file);
+ } else { // answer == no
- StringTokenizer tok;
- StringTokenizer deviceTok;
- String deviceInfo;
+ askManually(outputFile); // manually provide
configuration information
+ }
+ }
- String device;
- String deviceType;
- String[] devicesArray = new String[lines.length];
- for (int i=0; i<lines.length && lines[i] != null;
i++){
- tok = new StringTokenizer(lines[i],"%%%");
+ doc.setRootElement(store);
- // First the device info
- deviceInfo = tok.nextToken();
- deviceTok = new
StringTokenizer(deviceInfo,"@@@");
- device = deviceTok.nextToken();
- devicesArray[i] = device;
- deviceType = deviceTok.nextToken();
- if
(deviceType.equalsIgnoreCase("quaggatelnet")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.QuaggaAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".password", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".bgp.port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".bgp.prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".bgp.password", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- } else if
(deviceType.equalsIgnoreCase("ciscotelnet")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".username", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".password", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- } else if
(deviceType.equalsIgnoreCase("ciscossh")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".username", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".password", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- } else if
(deviceType.equalsIgnoreCase("ciscokey")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".username", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".keyUrl", "" + deviceTok.nextToken());
- if (deviceTok.hasMoreTokens())
-
prop.setProperty("service.r.mp." + device + ".passphrase", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- } else if
(deviceType.equalsIgnoreCase("junipertelnet")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".username", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".password", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- } else if
(deviceType.equalsIgnoreCase("juniperssh")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".username", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".password", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- } else if
(deviceType.equalsIgnoreCase("juniperkey")) {
- prop.setProperty("service.mp."+ device
- + ".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter");
- prop.setProperty("service.r.mp." +
device + ".url", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".port", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".prompt", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".rate", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".username", "" + deviceTok.nextToken());
- prop.setProperty("service.r.mp." +
device + ".keyUrl", "" + deviceTok.nextToken() + "\n");
- if (deviceTok.hasMoreTokens())
-
prop.setProperty("service.r.mp." + device + ".passphrase", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
+ XMLOutputter outputter = new XMLOutputter("\t", true);
+ try {
+ outputter.output(doc, new FileOutputStream(outputFile));
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ //prop.store(new FileOutputStream(outputFile), "Service.properties");
- } else {
- System.out.println("There was an
unknown device type in the csv file: "+deviceType);
- }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
- File tempFile =
File.createTempFile(device+"commands", ".tmp");
- DataOutputStream dos = new
DataOutputStream(new FileOutputStream(tempFile, true));
+ private void parseCSVFile(String file, String outputFile) {
+ try {
+ // Read all lines from txt file
+ lines = readLinesFromFile(file);
- while (tok.hasMoreTokens()) {
- //Then write all command info to a
temporary file
+ StringTokenizer tok;
+ StringTokenizer deviceTok;
+ String deviceInfo;
- dos.writeBytes(tok.nextToken()+"\n");
- dos.flush();
- }
+ String device;
+ String deviceType;
+ //String[] devicesArray = new String[lines.length];
- dos.close();
- //Then use this temporary file for writing
all command info
- addSelectedCommandsToConfig(device,
outputFile, tempFile.toString());
- }
+ System.out.println("[DEBUG] number of lines to be parsed: " +
lines.length);
- String tmp = "";
- for (int i=0; i<devicesArray.length &&
devicesArray[i] != null ; i++){
- tmp += devicesArray[i]+",";
- }
- prop.setProperty("service.mp.devices",
tmp.substring(0, tmp.length()-1));
-
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ for (int i = 0; i < lines.length && lines[i] != null; i++) {
- private String[] readLinesFromFile(String file) {
- ArrayList<String> lines = new ArrayList<String>();
+ System.out.println("[DEBUG] line: "+lines[i]);
- try {
- BufferedReader br = null;
- br = new BufferedReader(new FileReader(file));
- String line = "";
- line = br.readLine();
- while (line != null) {
- if (line != null && !line.equals(""))
- lines.add(line);
- line = br.readLine();
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ metadata = new Element("metadata", NMWG);
+ metadata.setAttribute("id", "metadata" + i);
- return lines.toArray(this.lines);
- }
+ tok = new StringTokenizer(lines[i], "%%%");
- private void askManually(String outputFile) {
- try{
- BufferedReader br = new BufferedReader(new
InputStreamReader(
- System.in));
+ // First the device info
+ deviceInfo = tok.nextToken();
+ deviceTok = new StringTokenizer(deviceInfo, "@@@");
+ device = deviceTok.nextToken();
- List devices = new ArrayList();
+ Element subject = new Element("subject", NMWG);
+ subject.setAttribute("id", "subject" + i);
+ subject.addContent(device);
+ metadata.addContent(subject);
- List types = new ArrayList();
- //List commands = new ArrayList();
+ //devicesArray[i] = device;
+ deviceType = deviceTok.nextToken();
- // service.properties (also in String format)
+ Element params = new Element("parameters", NMWG);
+ params.setAttribute("id", "metaParams" + i);
- System.out.println("First the names of the devices
that have to be supported will " +
- "be asked.\nHere you can specify
anything you like, but mostly this is the " +
- "URL or\nthe hostname of the machine.");
- System.out
- .println("Enter the name of the devices one by one,
end the list with \"STOP\"!");
- String input = "";
- while (!input.equalsIgnoreCase("STOP")) {
- input = br.readLine();
- if (input != null && !input.equals("") &&
!input.equalsIgnoreCase("STOP"))
- devices.add(input);
- }
+ Element param;
- String devicesString = "";
- if (devices.size() > 0) {
- Iterator it = devices.iterator();
- System.out.println(devices.size() + " devices
added.");
- //devicesString += it.next();
- //while (it.hasNext()) {
+ if (deviceType.equalsIgnoreCase("ciscotelnet")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter");
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "password");
+ param.setAttribute("value", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
+ metadata.addContent(params);
+ } else if (deviceType.equalsIgnoreCase("ciscossh")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter");
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "password");
+ param.setAttribute("value", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- System.out.println("");
- System.out
- .println("Choose one of the following types
of equipment for every ");
- System.out.println("device specified
previously ...");
- System.out.println("1) Quagga - Password
Login (Telnet)");
- System.out.println("2) Cisco - Password Login
(Telnet)");
- System.out.println("3) Cisco - Password Login
(SSH)");
- System.out.println("4) Cisco - Key-based
Login (SSH)");
- System.out.println("5) Juniper - Password
Login (Telnet)");
- System.out.println("6) Juniper - Password
Login (SSH)");
- System.out.println("7) Juniper - Key-based
Login (SSH)");
- System.out.println();
- Iterator it2 = devices.iterator();
+ metadata.addContent(params);
+ } else if (deviceType.equalsIgnoreCase("ciscokey")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter");
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "keyUrl");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ if (deviceTok.hasMoreTokens()) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "passphrase");
+ param.setAttribute("value", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
+ params.addContent(param);
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- String device = null;
- while (it2.hasNext()) {
- device = (String) it2.next();
- System.out.println(device + ": ");
- input = br.readLine();
- boolean invalid = true;
- while (invalid) {
- try {
- int t =
Integer.parseInt(input);
- if (t <= 7 && t > 0)
- invalid =
false;
- else {
-
System.out.println("Please provide a number between 1 and 7.");
- input =
br.readLine();
- }
- } catch
(NumberFormatException e) {
- invalid = true;
-
System.out.println("Please provide a number between 1 and 7.");
- input = br.readLine();
- }
- }
- types.add(input);
+ metadata.addContent(params);
+ } else if (deviceType.equalsIgnoreCase("junipertelnet")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter");
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "password");
+ param.setAttribute("value", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- if (input.equalsIgnoreCase("1"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.QuaggaAdapter");
- else if (input.equalsIgnoreCase("2"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter");
- else if (input.equalsIgnoreCase("3"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter");
+ metadata.addContent(params);
+ } else if (deviceType.equalsIgnoreCase("juniperssh")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter");
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "password");
+ param.setAttribute("value", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- else if (input.equalsIgnoreCase("4"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter");
+ metadata.addContent(params);
+ } else if (deviceType.equalsIgnoreCase("juniperkey")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter");
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "keyUrl");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + deviceTok.nextToken());
+ params.addContent(param);
+ if (deviceTok.hasMoreTokens()) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "passphrase");
+ param.setAttribute("value", "" +
PasswordEncryptor.encryptPassword(deviceTok.nextToken()));
+ params.addContent(param);
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- else if (input.equalsIgnoreCase("5"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter");
+ metadata.addContent(params);
+ } else {
+ System.out.println("There was an unknown device type in
the csv file: " + deviceType);
+ }
- else if (input.equalsIgnoreCase("6"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter");
+ store.addContent(metadata);
- else if (input.equalsIgnoreCase("7"))
- prop.setProperty("service.mp."
- + device
- +
".class_name",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter");
- }
- System.out.println();
- System.out.println("According to the chosen
type of device and access method, " +
- "some\nmore questions will be
asked to configure the URL, port, username,\n" +
- "password or key, prompt and
access-rate (Here you can specify what\n" +
- "the minimum interval has to be between
requests (in ms)).");
- //System.out.println("Now, some access
parameters will be asked ...");
- System.out.println();
- //}
- it = devices.iterator();
- int index = -1;
- String type = "";
- //String device = "";
- while (it.hasNext()) {
- device = (String) it.next();
- index = devices.indexOf(device);
- type = (String) types.get(index);
+ File tempFile = File.createTempFile(device + "commands",
".tmp");
+ DataOutputStream dos = new DataOutputStream(new
FileOutputStream(tempFile, true));
- //devicesString += it.next() + ",";
- devicesString +=device + ",";
- //System.out.println("devicesString:
"+devicesString);
- //if (previousDevices.equals(""))
- //
prop.setProperty("service.mp.devices=" +
devicesString.substring(0,devicesString.length()-1));
- //else
out.write("service.mp.devices=" + previousDevices +"," + devicesString +
"\n");
+ while (tok.hasMoreTokens()) {
+ //Then write all command info to a temporary file
+ String s = tok.nextToken();
+ dos.writeBytes(s + "\n");
+ dos.flush();
+ }
- System.out.println(device);
- System.out.println("======");
- System.out.println();
+ dos.close();
- if (type.equalsIgnoreCase("1")) {
- System.out.println("Please
give the hostname or IP address for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".url", input );
- System.out.println("Please
give the port for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".port", input);
- System.out
- .println("Please give the
prompt for device: " + device + ": ");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".prompt", input);
- System.out
- .println("Please give the
access rate for device (in ms): "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".rate", input);
- System.out
- .println("Please give the
password for device: "
- + device + ":
");
- input = br.readLine();
- while (input == null ||
input.equals("")){
- System.out.
- println("You have to
provide a password. Please give" +
- " the
password for device: "
- +
device + ": ");
- input = br.readLine();
- }
-
prop.setProperty("service.r.mp." + device + ".password",
PasswordEncryptor.encryptPassword(input));
- System.out
- .println("Please give the
bgp-daemon port for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + "bgp.port", input);
- System.out
- .println("Please give the
bgp-daemon prompt for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + "bgp.prompt", input);
- System.out
- .println("Please give the
bgp-daemon password for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + "bgp.password",
PasswordEncryptor.encryptPassword(input));
- } else if (type.equalsIgnoreCase("2")
- ||
type.equalsIgnoreCase("3")
- ||
type.equalsIgnoreCase("5")
- ||
type.equalsIgnoreCase("6")) {
- System.out.println("Please
give the hostname or IP address for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".url", input);
- System.out.println("Please
give the port for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".port", input);
- System.out
- .println("Please give the
prompt for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".prompt", input);
- System.out
- .println("Please give the
access rate for device (in ms): "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".rate", input);
- System.out
- .println("Please give the
username for device: "
- + device + ":
");
- input = br.readLine();
- while (input == null ||
input.equals("")){
- System.out
- .println("You have to
provide a username. " +
-
"Please give the username for device: "
- +
device + ": ");
- input = br.readLine();
- }
-
prop.setProperty("service.r.mp." + device + ".username", input);
- System.out
- .println("Please give the
password for device: "
- + device + ":
");
- input = br.readLine();
- while (input == null ||
input.equals("")){
- System.out
- .println("You have to
provide a password. " +
-
"Please give the password for device: "
- +
device + ": ");
- input = br.readLine();
- }
-
prop.setProperty("service.r.mp." + device + ".password",
PasswordEncryptor.encryptPassword(input));
-
//System.out.println("Encrypted password: " +
PasswordEncryptor.encryptPassword(input));
- } else if (type.equalsIgnoreCase("4")
- ||
type.equalsIgnoreCase("7")) {
- System.out.println("Please
give the hostname or IP address for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".url", input);
- System.out.println("Please
give the port for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".port", input);
- System.out
- .println("Please give the
prompt for device: "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".prompt", input);
- System.out
- .println("Please give the
access rate for device (in ms): "
- + device + ":
");
- input = br.readLine();
-
prop.setProperty("service.r.mp." + device + ".rate", input);
- System.out
- .println("Please give the
username for device: "
- + device + ":
");
- input = br.readLine();
- while (input == null ||
input.equals("")){
- System.out
- .println("You have to
provide a username. " +
-
"Please give the username for device: "
- +
device + ": ");
- input = br.readLine();
- }
-
prop.setProperty("service.r.mp." + device + ".username", input);
- System.out
- .println("Please give the
path to the public ssh key for device: "
- + device + ":
");
- input = br.readLine();
- while (input == null ||
input.equals("")){
- System.out
- .println("You have to
provide a path to the public ssh key. " +
-
"Please give the the path to the public ssh key for device: "
- +
device + ": ");
- input = br.readLine();
- }
-
prop.setProperty("service.r.mp." + device + ".keyUrl", input);
- System.out
- .println("Please provide the
passphrase for the public ssh key. " +
- "Leave this blank if you
don't have to enter a passphrase.");
- input = br.readLine();
- if (input != null &&
!input.equals("")){
-
prop.setProperty("service.r.mp." + device + ".passphrase",
PasswordEncryptor.encryptPassword(input));
- }
- }
+ data = new Element("data", NMWG);
+ data.setAttribute("id", "data" + i);
+ data.setAttribute("metadataIdRef", "metadata" + i);
- prop.setProperty("service.r.mp." +
device + ".cache", "0");
- System.out.println();
+ //Then use this temporary file for writing all command info
+ addSelectedCommandsToConfig(device, outputFile,
tempFile.toString());
- System.out
- .println("A predefined set of minimum
commands is provided. Do you wish to\n" +
- "use this set or do you want to build
a custom set? (yes/no)");
- input = br.readLine();
- while (!input.equals("yes") &&
!input.equals("no")){
- System.out.println("You have
to enter \"yes\" or \"no\".");
- input = br.readLine();
- }
+ store.addContent(data);
- if (input.equals("yes")){ // use
predefined set
+ }
- System.out.println("\nYou
chose to use the predefined set of commands. How\n" +
- "long (in ms)
should the results of the commands be cached in the MP?\n" +
- "As long as a
result for a certain command is cached, the MP will return\n" +
- "this cached result instead
of performing the command again.");
- int cachetime = 0;
- boolean valid = false;
- while (!valid){
- try {
- cachetime =
Integer.parseInt(br.readLine());
- if (cachetime
>= 0)
- valid
= true;
- else valid =
false;
- } catch
(NumberFormatException nfe) {
-
System.out.println("You have to enter a number.");
- valid = false;
- }
- }
+ /*String tmp = "";
+ for (int i=0; i<devicesArray.length && devicesArray[i] != null ;
i++){
+ tmp += devicesArray[i]+",";
+ }
+ prop.setProperty("service.mp.devices", tmp.substring(0,
tmp.length()-1));
+ */
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
- File tempFile =
File.createTempFile(device+"minimum", ".tmp");
+ private String[] readLinesFromFile(String file) {
+ ArrayList<String> lines = new ArrayList<String>();
- DataOutputStream tempout =
new DataOutputStream(new FileOutputStream(tempFile, true));
+ try {
+ BufferedReader br = null;
+ br = new BufferedReader(new FileReader(file));
+ String line = "";
+ line = br.readLine();
+ while (line != null) {
+ if (line != null && !line.equals("")) {
+ lines.add(line);
+ }
+ line = br.readLine();
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- File minimumFile;
- if
(type.equalsIgnoreCase("1")){
- minimumFile = new
File("conf/quagga"+MINIMUM_PACKAGE);
- if
(!minimumFile.exists())
- minimumFile =
new File("../conf/quagga"+MINIMUM_PACKAGE);
- } else if
(type.equalsIgnoreCase("2") || type.equalsIgnoreCase("3")
- ||
type.equalsIgnoreCase("4")){
- minimumFile = new
File("conf/cisco"+MINIMUM_PACKAGE);
- if
(!minimumFile.exists())
- minimumFile =
new File("../conf/cisco"+MINIMUM_PACKAGE);
- } else { // type == 5 or type
== 6 or type == 7
- minimumFile = new
File("conf/juniper"+MINIMUM_PACKAGE);
- if
(!minimumFile.exists())
- minimumFile =
new File("../conf/juniper"+MINIMUM_PACKAGE);
- }
- BufferedReader tempbr = new
BufferedReader(new FileReader(minimumFile));
+ return lines.toArray(this.lines);
+ }
- String in = tempbr.readLine();
+ private void askManually(String outputFile) {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));
- while (in != null &&
!in.equals("")) {
-
tempout.writeBytes(in.replace("@@@cache@@@", "@@@"+cachetime+"@@@")+"\n");
- in =
tempbr.readLine();
- }
+ List devices = new ArrayList();
-
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
- } else {
+ List types = new ArrayList();
- System.out.println("\nYou
will now be given the opportunity to select\n" +
- "the commands you wish the MP
supports.");
- if
(type.equalsIgnoreCase("2") || type.equalsIgnoreCase("3")
- ||
type.equalsIgnoreCase("4")) { // Cisco device
- File tempFile =
File.createTempFile("ciscominimum",".tmp");
-
System.out.println("\nFirst you can choose which IP-commands you wish to be
supported:");
-
selectCommands("cisco", "ip", tempFile.toString());
-
System.out.println("Select which IPv6-commands you wish to be supported:");
-
selectCommands("cisco", "ipv6", tempFile.toString());
-
System.out.println("Select which status commands you wish to be supported:");
-
selectCommands("cisco", "status", tempFile.toString());
-
System.out.println("Select which BGP-commands you wish to be supported:");
-
selectCommands("cisco", "bgp", tempFile.toString());
+ System.out.println("First the names of the devices that have to
be supported will " +
+ "be asked.\nHere you can specify anything you like, but
mostly this is the " +
+ "URL or\nthe hostname of the machine.");
+ System.out.println("Enter the name of the devices one by one,
end the list with \"STOP\"!");
+ String input = "";
+ while (!input.equalsIgnoreCase("STOP")) {
+ input = br.readLine();
+ if (input != null && !input.equals("") &&
!input.equalsIgnoreCase("STOP")) {
+ devices.add(input);
+ }
+ }
-
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
+ if (devices.size() > 0) {
+ Iterator it = devices.iterator();
+ System.out.println("****" + devices.size() + " devices
added.");
- tempFile.delete();
- } else if
(type.equalsIgnoreCase("5") || type.equalsIgnoreCase("6")
- ||
type.equalsIgnoreCase("7")) { // Juniper device
- File tempFile =
File.createTempFile("ciscominimum",".tmp");
-
System.out.println("\nFirst you can choose which IP-commands you wish to be
supported:");
-
selectCommands("juniper", "ip", tempFile.toString());
-
System.out.println("Select which IPv6-commands you wish to be supported:");
-
selectCommands("juniper", "ipv6", tempFile.toString());
-
System.out.println("Select which status commands you wish to be supported:");
-
selectCommands("juniper", "status", tempFile.toString());
-
System.out.println("Select which BGP-commands you wish to be supported:");
-
selectCommands("juniper", "bgp", tempFile.toString());
+ System.out.println("");
+ System.out.println("Choose one of the following types of
equipment for every ");
+ System.out.println("device specified previously ...");
+ System.out.println("1) Cisco - Password Login (Telnet)");
+ System.out.println("2) Cisco - Password Login (SSH)");
+ System.out.println("3) Cisco - Key-based Login (SSH)");
+ System.out.println("4) Juniper - Password Login (Telnet)");
+ System.out.println("5) Juniper - Password Login (SSH)");
+ System.out.println("6) Juniper - Key-based Login (SSH)");
+ System.out.println();
+ Iterator it2 = devices.iterator();
-
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
- tempFile.delete();
- } else if
(type.equalsIgnoreCase("1")) { // Quagga device
- File tempFile =
File.createTempFile("ciscominimum",".tmp");
-
System.out.println("\nFirst you can choose which IP-commands you wish to be
supported:");
-
selectCommands("quagga", "ip", tempFile.toString());
-
System.out.println("Select which IPv6-commands you wish to be supported:");
-
selectCommands("quagga", "ipv6", tempFile.toString());
-
System.out.println("Select which status commands you wish to be supported:");
-
selectCommands("quagga", "status", tempFile.toString());
-
System.out.println("Select which BGP-commands you wish to be supported:");
-
selectCommands("quagga", "bgp", tempFile.toString());
-
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
- tempFile.delete();
- } else { // Shouldn't happen
-
System.out.println("ERROR - Not a valid device.");
- }
- }
- }
- if (previousDevices.equals(""))
-
prop.setProperty("service.mp.devices",
devicesString.substring(0,devicesString.length()-1));
- else prop.setProperty("service.mp.devices",
previousDevices +"," + devicesString);
- }
- //out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ String device = null;
- System.out.println();
- System.out.println("That's all folks!");
- }
+ while (it2.hasNext()) {
+ device = (String) it2.next();
+ System.out.println(device + ": ");
+ input = br.readLine();
+ boolean invalid = true;
+ while (invalid) {
+ try {
+ int t = Integer.parseInt(input);
+ if (t <= 6 && t > 0) {
+ invalid = false;
+ } else {
+ System.out.println("Please provide a number
between 1 and 6.");
+ input = br.readLine();
+ }
+ } catch (NumberFormatException e) {
+ invalid = true;
+ System.out.println("Please provide a number
between 1 and 6.");
+ input = br.readLine();
+ }
+ }
+ types.add(input);
+ }
+ System.out.println();
- private void selectCommands(String device, String type, String
outFile) {
- File file = new File ("conf/"+device+type+"commands.txt");
- if (!file.exists())
- file = new File
("../conf/"+device+type+"commands.txt");
- try {
- System.out.println("File to use:
"+file.getCanonicalPath());
+ System.out.println("According to the chosen type of device
and access method, " +
+ "some\nmore questions will be asked to configure the
URL, port, username,\n" +
+ "password or key, prompt and access-rate (Here you
can specify what\n" +
+ "the minimum interval has to be between requests (in
ms)).");
+ System.out.println();
+ it = devices.iterator();
+ int index = -1;
+ String type = "";
+ while (it.hasNext()) {
+ device = (String) it.next();
+ index = devices.indexOf(device);
+ type = (String) types.get(index);
- BufferedReader br = new BufferedReader(new
FileReader(file));
- StringTokenizer tok = null;
+ System.out.println(device);
+ System.out.println("======");
+ System.out.println();
- BufferedReader in = new BufferedReader(
- new InputStreamReader(System.in));
+ metadata = new Element("metadata", NMWG);
+ metadata.setAttribute("id", "metadata" + index);
- String name = "";
- String command = "";
- String descr = "";
- String syntax = "";
- int index = 1;
+ Element subject = new Element("subject", NMWG);
+ subject.setAttribute("id", "subject0");
+ subject.addContent(device);
- String line = "";
- line = br.readLine();
- while (line != null) {
- tok = new StringTokenizer(line,"@@@");
- name = tok.nextToken();
- command = tok.nextToken();
- tok.nextToken(); // minimum parameters
- tok.nextToken(); // maxnimum parameters
- tok.nextToken(); // caching time
- descr = tok.nextToken();
- syntax = tok.nextToken();
- if (syntax.equals("---"))
- syntax = "";
- System.out.print(index);
- if (index++ > 9)
- System.out.print(" ");
- else System.out.print(" ");
- System.out.println(name+" : "+command+"
"+syntax+" ("+descr+")");
- line = br.readLine();
- }
- System.out.println("Enter the numbers of the commands
you wish to be supported. Enter \"STOP\" when you are finished");
- String input = "";
- input=in.readLine();
- boolean[] selected = new boolean[index-1];
- for (int j = 0; j<selected.length;j++)
- selected[j]=false;
- int i=0;
- boolean valid = false;
- while (!input.equalsIgnoreCase("STOP")){
- try {
- i = Integer.parseInt(input);
- if (i<index && i>0)
- valid = true;
- else {
- valid = false;
- System.out.println("Enter a
positive number less than "+index+" please.");
- }
- } catch (NumberFormatException e) {
- System.out.println("Enter a positive
number please.");
- valid = false;
- }
- if (valid)
- selected[i-1] = true;
- valid = false;
- input = in.readLine();
- }
+ metadata.addContent(subject);
- boolean noneselected = true;
- for (int id = 0; id<selected.length && noneselected;
id++){
- if (selected[id])
- noneselected = false;
- }
- if (!noneselected){
- System.out.println("Enter the caching time
for the selected commands.");
- input = in.readLine();
- boolean nan;
- int cache = 0;
- try {
- cache = Integer.parseInt(input);
- if (cache >= 0)
- nan = false;
- else nan = true;
- } catch (NumberFormatException nfe) {
- nan = true;
- }
- while (nan) {
- System.out.println("Enter a positive
number please.");
- input = in.readLine();
- try {
- cache =
Integer.parseInt(input);
- if (cache > 0)
- nan = false;
- else nan = true;
- } catch (NumberFormatException nfe) {
- nan = true;
- }
- }
+ Element params = new Element("parameters", NMWG);
+ params.setAttribute("id", "metaParams0");
- //File outputfile = new File("temp/" + device
+ "" + TEMPFILE);
- DataOutputStream dos = new
DataOutputStream(new FileOutputStream(outFile, true));
+ Element param;
- br = new BufferedReader(new
FileReader(file)); //go back to beginning of file
- line = br.readLine();
- int j=0;
- while (line!=null && !line.equals("")){
- if (selected[j]){
-
dos.writeBytes(line.replace("@@@cache@@@", "@@@"+cache+"@@@")+"\n");
- dos.flush();
- }
- j++;
- line = br.readLine();
- }
+ if (type.equalsIgnoreCase("1") ||
type.equalsIgnoreCase("2") || type.equalsIgnoreCase("4") ||
type.equalsIgnoreCase("5")) {
- br.close();
- dos.close();
- }
- System.out.println("\nChoosen commands temporarily
saved to file...\n");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
+ param = new Element("parameter", NMWG);
+ if (type.equalsIgnoreCase("1")) {
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter");
+ params.addContent(param);
+ } else if (type.equalsIgnoreCase("2")) {
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter");
+ params.addContent(param);
+ } else if (type.equalsIgnoreCase("4")) {
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter");
+ params.addContent(param);
+ } else if (type.equalsIgnoreCase("5")) {
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter");
+ params.addContent(param);
+ } else {
+ System.out.print("An error that should be
possible occured!");
+ }
- }
+ System.out.println("Please give the hostname or IP
address for device: " + device + ": ");
+ input = br.readLine();
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the port for device:
" + device + ": ");
+ input = br.readLine();
+ boolean valid = false;
+ while (!valid){
+ try {
+ if (Integer.parseInt(input) < 0) {
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the prompt for
device: " + device + ": ");
+ input = br.readLine();
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the access rate for
device (in ms): " + device + ": [default: 100]");
+ input = br.readLine();
+ valid = false;
+ while (!valid){
+ try {
+ if (input == null || input.equals(""))
+ input = "100";
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the username for
device: " + device + ": ");
+ input = br.readLine();
+ while (input == null || input.equals("")) {
+ System.out.println("You have to provide a
username. " +
+ "Please give the username for device: "
+ device + ": ");
+ input = br.readLine();
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "username");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the password for
device: " + device + ": ");
+ input = br.readLine();
+ while (input == null || input.equals("")) {
+ System.out.println("You have to provide a
password. " +
+ "Please give the password for device: "
+ device + ": ");
+ input = br.readLine();
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "password");
+ param.setAttribute("value",
PasswordEncryptor.encryptPassword(input));
+ params.addContent(param);
+ System.out.println("Please give the timeout for the
device: " + device + "\n(enter 0 or leave blank if you don't want to use a
timeout): ");
+ input = br.readLine();
+ valid = false;
+ while (!valid){
+ try {
+ if (input == null || input.equals(""))
+ input = "0";
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the maximum number
of users for the device: " + device + "\n(enter 0 or leave blank if you want
an unlimited amount of users): ");
+ input = br.readLine();
+ valid = false;
+ while (!valid){
+ try {
+ if (input == null || input.equals(""))
+ input = "0";
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + input);
+ params.addContent(param);
+
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- public void addSelectedCommandsToConfig(String device, String
outputFile, String inputFile) {
- File inputfile = new File(inputFile);
+ metadata.addContent(params);
+ } else if (type.equalsIgnoreCase("3") ||
type.equalsIgnoreCase("6")) {
- String input = "";
+ param = new Element("parameter", NMWG);
+ if (type.equalsIgnoreCase("3")) {
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter");
+ params.addContent(param);
+ } else if (type.equalsIgnoreCase("6")) {
+ param.setAttribute("name", "class_name");
+ param.setAttribute("value",
"org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter");
+ params.addContent(param);
- try {
- //add selected commands to the configuration
- File outputfile = new File(outputFile);
- //DataOutputStream out = new DataOutputStream(new
FileOutputStream(outputfile, true));
- FileOutputStream out = new
FileOutputStream(outputfile, true);
-
- BufferedReader br = new BufferedReader(new
FileReader(inputfile));
+ } else {
+ System.out.print("An error that should be
possible occured!");
+ }
- input = br.readLine();
+ System.out.println("Please give the hostname or IP
address for device: " + device + ": ");
+ input = br.readLine();
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "url");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the port for device:
" + device + ": ");
+ input = br.readLine();
+ boolean valid = false;
+ while (!valid){
+ try {
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "port");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the prompt for
device: " + device + ": ");
+ input = br.readLine();
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "prompt");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the access rate for
device (in ms): " + device + ": [default: 100]");
+ input = br.readLine();
+ valid = false;
+ while (!valid){
+ try {
+ if (input == null || input.equals(""))
+ input = "100";
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "rate");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the username for
device: " + device + ": ");
+ input = br.readLine();
+ param = new Element("parameter", NMWG);
+ while (input == null || input.equals("")) {
+ System.out.println("You have to provide a
username. " +
+ "Please give the username for device: "
+ device + ": ");
+ input = br.readLine();
+ }
+ param.setAttribute("name", "username");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the path to the
public ssh key for device: " + device + ": ");
+ input = br.readLine();
+ param = new Element("parameter", NMWG);
+ while (input == null || input.equals("")) {
+ System.out.println("You have to provide a path
to the public ssh key. " +
+ "Please give the the path to the public
ssh key for device: " + device + ": ");
+ input = br.readLine();
+ }
+ param.setAttribute("name", "keyUrl");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please provide the passphrase
for the public ssh key. " +
+ "Leave this blank if you don't have to enter
a passphrase.");
+ input = br.readLine();
- String command = "";
- String realCommand = "";
- String minParamCount = "";
- String maxParamCount = "";
- String cache = "";
- String description = "";
- String syntax = "";
- String regExp = "";
+ if (input != null && !input.equals("")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "passphrase");
+ param.setAttribute("value",
PasswordEncryptor.encryptPassword(input));
+ params.addContent(param);
- StringTokenizer tok;
+ }
- String commandList = "";
+ System.out.println("Please give the timeout for the
device: " + device + "\n(enter 0 or leave blank if you don't want to use a
timeout): ");
+ input = br.readLine();
+ valid = false;
+ while (!valid){
+ try {
+ if (input == null || input.equals(""))
+ input = "0";
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "timeout");
+ param.setAttribute("value", input);
+ params.addContent(param);
+ System.out.println("Please give the maximum number
of users for the device: " + device + "\n(enter 0 or leave blank if you want
an unlimited amount of users): ");
+ input = br.readLine();
+ valid = false;
+ while (!valid){
+ try {
+ if (input == null || input.equals(""))
+ input = "0";
+ if (Integer.parseInt(input) < 0){
+ System.out.println("Please
provide a positive number.");
+ input = br.readLine();
+ }
+ else valid = true;
+ } catch (NumberFormatException nfe) {
+ System.out.println("Please provide a
positive number.");
+ input = br.readLine();
+ }
+ }
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "numberOfUsers");
+ param.setAttribute("value", "" + input);
+ params.addContent(param);
+
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);
- while (input != null && !input.equals("")){
- tok = new StringTokenizer(input, "@@@");
+ metadata.addContent(params);
+ }
- command = tok.nextToken();
- realCommand = tok.nextToken();
- minParamCount = tok.nextToken();
- maxParamCount = tok.nextToken();
- cache = tok.nextToken();
- description = tok.nextToken();
- syntax = tok.nextToken();
- regExp = tok.nextToken();
+ store.addContent(metadata);
- commandList += command + ",";
+ System.out.println();
- prop.setProperty("service.mp." + device +
".commands." + command + "", realCommand);
- //out.flush();
- if (!minParamCount.equalsIgnoreCase("---")) {
- prop.setProperty("service.mp." +
device + ".commands."
- + command +
".minParamCount", minParamCount);
- //out.flush();
- }
+ System.out.println("A predefined set of minimum commands
is provided. Do you wish to\n" +
+ "use this set or do you want to build a custom
set? (yes/no)");
+ input = br.readLine();
+ while (!input.equals("yes") && !input.equals("no")) {
+ System.out.println("You have to enter \"yes\" or
\"no\".");
+ input = br.readLine();
+ }
- if (!maxParamCount.equalsIgnoreCase("---")) {
- prop.setProperty("service.mp." +
device + ".commands."
- + command +
".maxParamCount", maxParamCount);
- //out.flush();
- }
+ if (input.equals("yes")) { // use predefined set
- if (!cache.equalsIgnoreCase("---")) {
- prop.setProperty("service.mp." +
device + ".commands."
- + command +
".caching", cache);
- //out.flush();
- }
- if (!description.equalsIgnoreCase("---")) {
- prop.setProperty("service.mp." +
device + ".commands."
- + command +
".description", description);
- //out.flush();
- }
+ System.out.println("\nYou chose to use the
predefined set of commands. How\n" +
+ "long (in ms) should the results of the
commands be cached in the MP?\n" +
+ "As long as a result for a certain command
is cached, the MP will return\n" +
+ "this cached result instead of performing
the command again.");
+ int cachetime = 0;
+ boolean valid = false;
+ while (!valid) {
+ try {
+ cachetime = Integer.parseInt(br.readLine());
+ if (cachetime >= 0) {
+ valid = true;
+ } else {
+ valid = false;
+ }
+ } catch (NumberFormatException nfe) {
+ System.out.println("You have to enter a
number.");
+ valid = false;
+ }
+ }
- if (!syntax.equalsIgnoreCase("---")) {
- prop.setProperty("service.mp." +
device + ".commands."
- + command +
".syntax", syntax);
- //out.flush();
- }
+ File tempFile = File.createTempFile(device +
"minimum", ".tmp");
- if (!regExp.equalsIgnoreCase("---")) {
- prop.setProperty("service.mp." +
device + ".commands."
- + command + ".regex",
regExp);
- //out.flush();
- }
- input = br.readLine();
- }
- commandList = commandList.substring(0,
commandList.length()-1);
- prop.setProperty("service.mp." + device +
".commands", commandList);
- //out.flush();
+ DataOutputStream tempout = new DataOutputStream(new
FileOutputStream(tempFile, true));
- out.close();
+ File minimumFile;
+ if (type.equalsIgnoreCase("1") ||
type.equalsIgnoreCase("2") || type.equalsIgnoreCase("3")) {
+ minimumFile = new File("conf/cisco" +
MINIMUM_PACKAGE);
+ if (!minimumFile.exists()) {
+ minimumFile = new File("../conf/cisco" +
MINIMUM_PACKAGE);
+ }
+ } else { // type == 5 or type == 6 or type == 7
+ minimumFile = new File("conf/juniper" +
MINIMUM_PACKAGE);
+ if (!minimumFile.exists()) {
+ minimumFile = new File("../conf/juniper" +
MINIMUM_PACKAGE);
+ }
+ }
+ BufferedReader tempbr = new BufferedReader(new
FileReader(minimumFile));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
- inputfile.delete();
- }
+ String in = tempbr.readLine();
- public static void main(String[] args) {
- try {
- if (args.length != 1 && args.length != 2) {
- System.err.println("Wrong number of
arguments!");
- System.exit(0);
- } else {
- //System.out.println(args[0]);
- ServicePropertiesConfigurator stitcher = new
ServicePropertiesConfigurator();
- stitcher.doStuff(args[0]);
- //createServiceStorageXML(args[0], args[0] +
"XML.xml");
- }
- } catch (RuntimeException e) {
- } catch (Exception e){
- e.printStackTrace();
- }
- }
+ while (in != null && !in.equals("")) {
+ tempout.writeBytes(in.replace("@@@cache@@@",
"@@@" + cachetime + "@@@") + "\n");
+ in = tempbr.readLine();
+ }
+
+ data = new Element("data", NMWG);
+ data.setAttribute("id", "data" + index);
+ data.setAttribute("metadataIdRef", "metadata" +
index);
+
+ addSelectedCommandsToConfig(device, outputFile,
tempFile.toString());
+
+ store.addContent(data);
+
+ tempFile.delete();
+ } else {
+
+ System.out.println("\nYou will now be given the
opportunity to select\n" +
+ "the commands you wish the MP supports.");
+ if (type.equalsIgnoreCase("1") ||
type.equalsIgnoreCase("2") || type.equalsIgnoreCase("3")) { // Cisco device
+ File tempFile =
File.createTempFile("ciscominimum", ".tmp");
+ System.out.println("\nFirst you can choose which
IP-commands you wish to be supported:");
+ selectCommands("cisco", "ip",
tempFile.toString());
+ System.out.println("Select which IPv6-commands
you wish to be supported:");
+ selectCommands("cisco", "ipv6",
tempFile.toString());
+ System.out.println("Select which status commands
you wish to be supported:");
+ selectCommands("cisco", "status",
tempFile.toString());
+ System.out.println("Select which BGP-commands
you wish to be supported:");
+ selectCommands("cisco", "bgp",
tempFile.toString());
+
+ //System.out.println("[DEBUG] Commands
Selected");
+
+ data = new Element("data", NMWG);
+ data.setAttribute("id", "data" + index);
+ data.setAttribute("metadataIdRef", "metadata" +
index);
+
+ //System.out.println("[DEBUG] XML elements
created");
+
+ addSelectedCommandsToConfig(device, outputFile,
tempFile.toString());
+
+ //System.out.println("[DEBUG] Selected commands
added to configfile");
+
+ store.addContent(data);
+
+ //System.out.println("[DEBUG] data XML element
added to root element");
+
+ tempFile.delete();
+
+ //System.out.println("[DEBUG] temporary file
deleted");
+ } else if (type.equalsIgnoreCase("4") ||
type.equalsIgnoreCase("5") || type.equalsIgnoreCase("6")) { // Juniper device
+ File tempFile =
File.createTempFile("ciscominimum", ".tmp");
+ System.out.println("\nFirst you can choose which
IP-commands you wish to be supported:");
+ selectCommands("juniper", "ip",
tempFile.toString());
+ System.out.println("Select which IPv6-commands
you wish to be supported:");
+ selectCommands("juniper", "ipv6",
tempFile.toString());
+ System.out.println("Select which status commands
you wish to be supported:");
+ selectCommands("juniper", "status",
tempFile.toString());
+ System.out.println("Select which BGP-commands
you wish to be supported:");
+ selectCommands("juniper", "bgp",
tempFile.toString());
+
+ //System.out.println("[DEBUG] Commands
Selected");
+
+ data = new Element("data", NMWG);
+ data.setAttribute("id", "data" + index);
+ data.setAttribute("metadataIdRef", "metadata" +
index);
+
+ //System.out.println("[DEBUG] XML elements
created");
+
+ addSelectedCommandsToConfig(device, outputFile,
tempFile.toString());
+
+ //System.out.println("[DEBUG] Selected commands
added to configfile");
+
+ store.addContent(data);
+
+ //System.out.println("[DEBUG] data XML element
added to root element");
+
+ tempFile.delete();
+
+ //System.out.println("[DEBUG] temporary file
deleted");
+ } else { // Shouldn't happen
+ System.out.println("ERROR - Not a valid
device.");
+ }
+ }
+ //System.out.println("[DEBUG] There are more devices: "
+ it.hasNext());
+ }
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ System.out.println();
+ System.out.println("That's all folks!");
+ }
+
+ private void selectCommands(String device, String type, String outFile) {
+ File file = new File("conf/" + device + type + "commands.txt");
+ if (!file.exists()) {
+ file = new File("../conf/" + device + type + "commands.txt");
+ }
+ try {
+ System.out.println("File to use: " + file.getCanonicalPath());
+
+ BufferedReader br = new BufferedReader(new FileReader(file));
+ StringTokenizer tok = null;
+
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(System.in));
+
+ String name = "";
+ String command = "";
+ String descr = "";
+ String syntax = "";
+ int index = 1;
+
+ String line = "";
+ line = br.readLine();
+ while (line != null) {
+ tok = new StringTokenizer(line, "@@@");
+ name = tok.nextToken();
+ command = tok.nextToken();
+ tok.nextToken(); // minimum parameters
+ tok.nextToken(); // maxnimum parameters
+ tok.nextToken(); // caching time
+ descr = tok.nextToken();
+ syntax = tok.nextToken();
+ if (syntax.equals("---")) {
+ syntax = "";
+ }
+ System.out.print(index);
+ if (index++ > 9) {
+ System.out.print(" ");
+ } else {
+ System.out.print(" ");
+ }
+ System.out.println(name + " : " + command + " " + syntax + "
(" + descr + ")");
+ line = br.readLine();
+ }
+ System.out.println("Enter the numbers of the commands you wish
to be supported. Enter \"STOP\" when you are finished");
+ String input = "";
+ input = in.readLine();
+ boolean[] selected = new boolean[index - 1];
+ for (int j = 0; j < selected.length; j++) {
+ selected[j] = false;
+ }
+ int i = 0;
+ boolean valid = false;
+ while (!input.equalsIgnoreCase("STOP")) {
+ try {
+ i = Integer.parseInt(input);
+ if (i < index && i > 0) {
+ valid = true;
+ } else {
+ valid = false;
+ System.out.println("Enter a positive number less
than " + index + " please.");
+ }
+ } catch (NumberFormatException e) {
+ System.out.println("Enter a positive number please.");
+ valid = false;
+ }
+ if (valid) {
+ selected[i - 1] = true;
+ }
+ valid = false;
+ input = in.readLine();
+ }
+
+ boolean noneselected = true;
+ for (int id = 0; id < selected.length && noneselected; id++) {
+ if (selected[id]) {
+ noneselected = false;
+ }
+ }
+ if (!noneselected) {
+ System.out.println("Enter the caching time for the selected
commands.");
+ input = in.readLine();
+ boolean nan;
+ int cache = 0;
+ try {
+ cache = Integer.parseInt(input);
+ if (cache >= 0) {
+ nan = false;
+ } else {
+ nan = true;
+ }
+ } catch (NumberFormatException nfe) {
+ nan = true;
+ }
+ while (nan) {
+ System.out.println("Enter a positive number please.");
+ input = in.readLine();
+ try {
+ cache = Integer.parseInt(input);
+ if (cache > 0) {
+ nan = false;
+ } else {
+ nan = true;
+ }
+ } catch (NumberFormatException nfe) {
+ nan = true;
+ }
+ }
+
+ DataOutputStream dos = new DataOutputStream(new
FileOutputStream(outFile, true));
+
+ br = new BufferedReader(new FileReader(file)); //go back to
beginning of file
+ line = br.readLine();
+ int j = 0;
+ while (line != null && !line.equals("")) {
+ if (selected[j]) {
+ dos.writeBytes(line.replace("@@@cache@@@", "@@@" +
cache + "@@@") + "\n");
+ dos.flush();
+ }
+ j++;
+ line = br.readLine();
+ }
+
+ br.close();
+ dos.close();
+ }
+ //System.out.println("\n[DEBUG] Choosen commands temporarily
saved to file...\n");
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
+
+ }
+
+ public void addSelectedCommandsToConfig(String device, String
outputFile, String inputFile) {
+ File inputfile = new File(inputFile);
+
+ String input = "";
+
+ try {
+ BufferedReader br = new BufferedReader(new
FileReader(inputfile));
+
+ input = br.readLine();
+
+ String command = "";
+ String realCommand = "";
+ String minParamCount = "";
+ String maxParamCount = "";
+ String cache = "";
+ String description = "";
+ String syntax = "";
+ String regExp = "";
+
+ StringTokenizer tok;
+
+ Element key;
+
+ Element params;
+ Element param;
+
+ Element eventType;
+
+ while (input != null && !input.equals("")) {
+ tok = new StringTokenizer(input, "@@@");
+
+ key = new Element("key", NMWG);
+
+ params = new Element("parameters", NMWG);
+ params.setAttribute("id", "params0");
+
+ command = tok.nextToken();
+ realCommand = tok.nextToken();
+ minParamCount = tok.nextToken();
+ maxParamCount = tok.nextToken();
+ //System.out.println("[DEBUG] MaxParamCount: " +
maxParamCount);
+ cache = tok.nextToken();
+ //System.out.println("[DEBUG] Cache: " + cache);
+ description = tok.nextToken();
+ //System.out.println("[DEBUG] Description: " + description);
+ syntax = tok.nextToken();
+ //System.out.println("[DEBUG] Syntax: " + syntax);
+ regExp = tok.nextToken();
+ //System.out.println("[DEBUG] RegExp: " + regExp);
+
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "command");
+ param.setAttribute("value", realCommand);
+ params.addContent(param);
+
+ if (!minParamCount.equalsIgnoreCase("---")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "minParamCount");
+ param.setAttribute("value", minParamCount);
+ params.addContent(param);
+ }
+
+ if (!maxParamCount.equalsIgnoreCase("---")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "maxParamCount");
+ param.setAttribute("value", maxParamCount);
+ params.addContent(param);
+ }
+
+ if (!cache.equalsIgnoreCase("---")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "caching");
+ param.setAttribute("value", cache);
+ params.addContent(param);
+ }
+
+ if (!description.equalsIgnoreCase("---")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "description");
+ param.setAttribute("value", description);
+ params.addContent(param);
+ }
+
+ if (!syntax.equalsIgnoreCase("---")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "syntax");
+ param.setAttribute("value", syntax);
+ params.addContent(param);
+ }
+
+ if (!regExp.equalsIgnoreCase("---")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "regex");
+ param.setAttribute("value", regExp);
+ params.addContent(param);
+ }
+ //System.out.println("[DEBUG] parameter elements made...");
+
+ eventType = new Element("eventType", NMWG);
+ eventType.addContent(EVENTTYPE_PREFIX + command + "/" +
EVENTTYPE_VERSION);
+
+ key.addContent(eventType);
+ //System.out.println("[DEBUG] eventTypes added to key
element...");
+ key.addContent(params);
+ //System.out.println("[DEBUG] parameters added to key
element...");
+ data.addContent(key);
+ //System.out.println("[DEBUG] key added to data element...");
+
+
+ //System.out.println("[DEBUG] Number of keys inside the data
element: "+data.getChildren("key", NMWG).size());
+
+ input = br.readLine();
+ //System.out.println("[DEBUG] Line read: " + input);
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ } catch (IllegalAddException iae) {
+ iae.printStackTrace();
+ }
+ inputfile.delete();
+ }
+
+ public static void main(String[] args) {
+ try {
+ if (args.length != 1 && args.length != 2) {
+ System.err.println("Wrong number of arguments!");
+ System.exit(0);
+ } else {
+ ServicePropertiesConfigurator stitcher = new
ServicePropertiesConfigurator();
+ stitcher.doStuff(args[0]);
+ }
+ } catch (RuntimeException e) {
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on February, 7th 2007
- * Version Number: 0.6
+ * Created/Updated on January, 8th 2008
+ * Version Number: 1.0
* Project: perfSonar
*
* Stijn Verstichel
()
@@ -9,11 +9,19 @@
package
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters;
import java.awt.Toolkit;
-import java.util.ArrayList;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Provider.Service;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
+import javax.crypto.Cipher;
+import javax.swing.SwingUtilities;
+
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.EventType;
import org.ggf.ns.nmwg.base.v2_0.Message;
@@ -25,12 +33,15 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ActionType;
import org.perfsonar.service.base.engine.ServiceEngine;
+//import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
+
/**
* Implementation class that filters and forwards request based upon the
* requested device in the subject of the requestMessage.
@@ -42,570 +53,509 @@
*/
public class WebserviceEngineAdapter implements ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
+ private Message[] messages;
+ private static int[] count;
- private Message[] messages;
+ // ---------------------- class-fields
+ private LoggerComponent logger = null;
+ private MetadataConfiguration configuration = null;
+ // List of all supported devices, populated from the service.properties
+ // files
+ private List devices = null;
- private static int count = 0;
+ private static boolean arrayInitialized = false;
+
- // ---------------------- class-fields
+ // ---------------------- constructors
+ public WebserviceEngineAdapter() throws PerfSONARException {
- private LoggerComponent logger = null;
+ try {
- private PropertiesConfigurationComponent properties = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- // List of all supported devices, populated from the
service.properties
- // files
- private List devices = null;
+ this.logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().
+ getComponent(ComponentNames.LOGGER);
- // ---------------------- constructors
+ this.configuration = new DbMetadataConfiguration();
+ configuration.initStorage();
- public WebserviceEngineAdapter() throws PerfSONARException {
+ devices =
configuration.getProperties(MetadataConfiguration.DEVICE_NAMES);
- try {
+ registerServiceWithLS();
+
+ if (!arrayInitialized){
+ count = new int[devices.size()];
+ arrayInitialized = true;
+ }
+
+ //for (int i = 0; i < count.length; i++)
+ // count[i] = 0;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- StringTokenizer devicesTokenizer = null;
- devices = new ArrayList();
+ } catch (PerfSONARException e) {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+
logger.error("[WEBSERVICEENGINEADAPTER][Constructor]"+e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }
- devicesTokenizer = new StringTokenizer(properties
- .getProperty("service.mp.devices"),
",");
- while (devicesTokenizer.hasMoreTokens()) {
+ }// WebserviceEngineAdapter
- devices.add(devicesTokenizer.nextToken());
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- registerServiceWithLS();
+ }
- } catch (PerfSONARException e) {
+ /**
+ * @see ServiceEngine.java
+ */
+
+
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.info("[WebserviceEngineAdapter] Webservice takeAction call
received");
- }
+ Metadata[] requestMetadata = request.getMetadataArray();
+ Data[] requestData = request.getDataArray();
- }// WebserviceEngineAdapter
+ if (actionType.equalsIgnoreCase(ActionType.GET_KEY)) {
- // ---------------------- Methods from service engine interface
+ return createServiceCapabilitiesResponse(request);
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } // Find the correct handler for the device requested
+ else {
- return this.serviceEngineType;
+ logger.debug("NUMBER OF BLOCKs: " + requestMetadata.length);
- }
+ messages = new Message[requestMetadata.length];
+ RequestMonitor requestMonitor = new RequestMonitor(
+ requestMetadata.length);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ int[] currentDevices = new int[requestMetadata.length];
+ for (int i = 0; i < currentDevices.length; i++)
+ currentDevices[i] = -1;
+
+ for (int i = 0; i < requestMetadata.length; i++) {
+ Subject subjectTemp = requestMetadata[i].getSubject();
+ boolean deviceElementOK = true;
+ String value = "";
- logger
- .info("[WebserviceEngineAdapter] Webservice
takeAction call received");
- // System.out.println("[WebserviceEngineAdapter] Webservice
takeAction
- // call received");
+ try {
+ EndPoint endpoint = (EndPoint)
subjectTemp.getChildArray()[0];
+ value = endpoint.getValue();
+ } catch (Exception e) {
+ deviceElementOK = false;
+ }
- logger.info("COUNT: " + count++);
+ if (deviceElementOK && devices.contains(value)) {
- Metadata[] requestMetadata = request.getMetadataArray();
- Data[] requestData = request.getDataArray();
-
- if (actionType.equalsIgnoreCase(ActionType.GET_KEY)) {
+ logger.debug("Device: " + value);
+ logger.debug("Device index: " +
devices.indexOf(value));
+ count[devices.indexOf(value)]++;
+ currentDevices[i] = devices.indexOf(value);
//contains the indexes of the devices in use
+ logger.debug("Number of current connections for
device \"" + value + "\": " + count[currentDevices[i]]);
+
+ if (Integer.parseInt(configuration.getProperty(value,
"numberOfUsers")) <= 0 // numberOfUsers <= 0 --> unlimited amount of users
+ || count[devices.indexOf(value)] <=
Integer.parseInt(configuration.getProperty(value, "numberOfUsers"))){
+
+ Message message = new Message();
+ message.setMetadata(requestMetadata[i]);
+ String metadataIdRef = requestMetadata[i].getId();
+
+ for (int j = 0; j < requestData.length; j++) {
+ if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
+ metadataIdRef)) {
+ message.setData(requestData[j]);
+ }
+ }
+
+ String serviceEngineString =
configuration.getProperty(value, "class_name");
+
+ //RequestExecutingThread requestExecutingThread =
new RequestExecutingThread(
+ // i, actionType, serviceEngineString,
message,
+ // requestMetadata[i], requestMonitor,
Long.parseLong(configuration.getProperty(value, "timeout")));
+
+ RequestExecutingThread requestExecutingThread =
new RequestExecutingThread(
+ i, actionType, serviceEngineString,
message,
+ requestMetadata[i], requestMonitor);
+
+ requestExecutingThread.start();
+ } else {
+ messages[i] = new Message();
+ messages[i].setMetadata(requestMetadata[i]);
+ String metadataIdRef = requestMetadata[i].getId();
- return createServiceCapabilitiesResponse(request);
+ for (int j = 0; j < requestData.length; j++) {
+ if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
+ metadataIdRef)) {
+ messages[i].setData(requestData[j]);
+ }
+ }
- }
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
requestMetadata[i].getId());
- // Find the correct handler for the device requested
- else {
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
requestMetadata[i].getId());
+
resultCodeSubject.setMetadataIdRef(requestMetadata[i].getId());
- logger.debug("NUMBER OF BLOCKs: " +
requestMetadata.length);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
requestMetadata[i].getId());
+
resultCodeEventType.setEventType("error.mp.sshtelnet.device");
- messages = new Message[requestMetadata.length];
- RequestMonitor requestMonitor = new RequestMonitor(
- requestMetadata.length);
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);
- for (int i = 0; i < requestMetadata.length; i++) {
- Subject subjectTemp =
requestMetadata[i].getSubject();
- boolean deviceElementOK = true;
- String value = "";
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" +
requestMetadata[i].getId());
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
requestMetadata[i].getId());
- try {
- EndPoint endpoint = (EndPoint)
subjectTemp.getChildArray()[0];
- value = endpoint.getValue();
- } catch (Exception e) {
- deviceElementOK = false;
- }
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" +
requestMetadata[i].getId());
+ resultCodeDatum.setValue("Too many concurrent
connections to the device. Please try again later.");
+
+ resultCodeData.addChild(resultCodeDatum);
- if (deviceElementOK &&
devices.contains(value)) {
+ messages[i].setMetadata(resultCodeMetadata);
+ messages[i].setData(resultCodeData);
- Message message = new Message();
-
message.setMetadata(requestMetadata[i]);
- String metadataIdRef =
requestMetadata[i].getId();
+ requestMonitor.setCompleted(i, null);
+ }
- for (int j = 0; j <
requestData.length; j++)
- if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
-
metadataIdRef))
-
message.setData(requestData[j]);
+ } else {
- String serviceEngineString =
properties
-
.getProperty("service.mp." + value + ".class_name");
+ messages[i] = new Message();
+ messages[i].setMetadata(requestMetadata[i]);
+ String metadataIdRef = requestMetadata[i].getId();
- RequestExecutingThread
requestExecutingThread = new RequestExecutingThread(
- i, actionType,
serviceEngineString, message,
- requestMetadata[i],
requestMonitor);
+ for (int j = 0; j < requestData.length; j++) {
+ if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
+ metadataIdRef)) {
+ messages[i].setData(requestData[j]);
+ }
+ }
- requestExecutingThread.start();
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
requestMetadata[i].getId());
- /**
- * try { Message message = new
Message();
- *
message.setMetadata(requestMetadata[i]); String
- * metadataIdRef =
requestMetadata[i].getId();
- *
- * for (int j = 0; j <
requestData.length; j++) if
- * (requestData[j].getMetadataIdRef()
- * .equalsIgnoreCase(metadataIdRef))
- * message.setData(requestData[j]);
- *
- * ServiceEngine serviceEngine =
ServiceEngineFactory
- * .getServiceEngine(properties
.getProperty("service.mp." +
- * value + ".class_name"));
messages[i] =
- *
serviceEngine.takeAction(actionType, message);
- * // Inclusion of the result code
tags Metadata
- * resultCodeMetadata = new
Metadata();
- *
resultCodeMetadata.setId("resultCodeMeta_" +
- * requestMetadata[i].getId());
- *
- * Subject resultCodeSubject = new
Subject();
- *
resultCodeSubject.setId("resultCodeSubj_" +
- * requestMetadata[i].getId());
- *
resultCodeSubject.setMetadataIdRef(requestMetadata[i]
- * .getId());
- *
- * EventType resultCodeEventType =
new EventType();
- *
resultCodeEventType.setId("resultCodeEventType_" +
- * requestMetadata[i].getId());
resultCodeEventType
- *
.setEventType("success.mp.sshtelnet");
- *
- *
resultCodeMetadata.addChild(resultCodeSubject);
- *
resultCodeMetadata.addChild(resultCodeEventType);
- *
- * Data resultCodeData = new Data();
- *
resultCodeData.setId("resultCodeData_" +
- * requestMetadata[i].getId());
- *
resultCodeData.setMetadataIdRef("resultCodeMeta_" +
- * requestMetadata[i].getId());
- *
- * Datum resultCodeDatum = new
Datum();
- *
resultCodeDatum.setId("resultCodeDatum_" +
- * requestMetadata[i].getId());
resultCodeDatum
- * .setValue("Successfully executed
request");
- *
- *
resultCodeData.addChild(resultCodeDatum);
- *
- *
messages[i].setMetadata(resultCodeMetadata);
- *
messages[i].setData(resultCodeData);
- * } catch (PerfSONARException e) {
- *
- * messages[i] = new Message();
- *
messages[i].setMetadata(requestMetadata[i]); String
- * metadataIdRef =
requestMetadata[i].getId();
- *
- * for (int j = 0; j <
requestData.length; j++) if
- * (requestData[j].getMetadataIdRef()
- * .equalsIgnoreCase(metadataIdRef))
- *
messages[i].setData(requestData[j]);
- *
- * Metadata resultCodeMetadata = new
Metadata();
- *
resultCodeMetadata.setId("resultCodeMeta_" +
- * requestMetadata[i].getId());
- *
- * Subject resultCodeSubject = new
Subject();
- *
resultCodeSubject.setId("resultCodeSubj_" +
- * requestMetadata[i].getId());
- *
resultCodeSubject.setMetadataIdRef(requestMetadata[i]
- * .getId());
- *
- * EventType resultCodeEventType =
new EventType();
- *
resultCodeEventType.setId("resultCodeEventType_" +
- * requestMetadata[i].getId());
- *
resultCodeEventType.setEventType(e.getResultCode());
- *
- *
resultCodeMetadata.addChild(resultCodeSubject);
- *
resultCodeMetadata.addChild(resultCodeEventType);
- *
- * Data resultCodeData = new Data();
- *
resultCodeData.setId("resultCodeData_" +
- * requestMetadata[i].getId());
- *
resultCodeData.setMetadataIdRef("resultCodeMeta_" +
- * requestMetadata[i].getId());
- *
- * Datum resultCodeDatum = new
Datum();
- *
resultCodeDatum.setId("resultCodeDatum_" +
- * requestMetadata[i].getId());
- *
resultCodeDatum.setValue(e.getResultDescription());
- *
- *
resultCodeData.addChild(resultCodeDatum);
- *
- *
messages[i].setMetadata(resultCodeMetadata);
- *
messages[i].setData(resultCodeData);
- *
- *
logger.error(e.getResultDescription()); }
- */
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
requestMetadata[i].getId());
+
resultCodeSubject.setMetadataIdRef(requestMetadata[i].getId());
- } else {
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
requestMetadata[i].getId());
+
resultCodeEventType.setEventType("error.mp.sshtelnet.device");
- messages[i] = new Message();
-
messages[i].setMetadata(requestMetadata[i]);
- String metadataIdRef =
requestMetadata[i].getId();
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);
- for (int j = 0; j <
requestData.length; j++)
- if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
-
metadataIdRef))
-
messages[i].setData(requestData[j]);
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" +
requestMetadata[i].getId());
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
requestMetadata[i].getId());
- Metadata resultCodeMetadata = new
Metadata();
-
resultCodeMetadata.setId("resultCodeMeta_"
- +
requestMetadata[i].getId());
+ Datum resultCodeDatum = null;
+ if (deviceElementOK) {
+ resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" +
requestMetadata[i].getId());
+ resultCodeDatum.setValue("Requested device not
supported");
+ } else {
+ resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" +
requestMetadata[i].getId());
+ resultCodeDatum.setValue("No Device element given in
request");
+ }
- Subject resultCodeSubject = new
Subject();
-
resultCodeSubject.setId("resultCodeSubj_"
- +
requestMetadata[i].getId());
-
resultCodeSubject.setMetadataIdRef(requestMetadata[i]
- .getId());
+ resultCodeData.addChild(resultCodeDatum);
- EventType resultCodeEventType = new
EventType();
-
resultCodeEventType.setId("resultCodeEventType_"
- +
requestMetadata[i].getId());
- resultCodeEventType
-
.setEventType("error.mp.sshtelnet.device");
+ messages[i].setMetadata(resultCodeMetadata);
+ messages[i].setData(resultCodeData);
-
resultCodeMetadata.addChild(resultCodeSubject);
-
resultCodeMetadata.addChild(resultCodeEventType);
+ requestMonitor.setCompleted(i, null);
- Data resultCodeData = new Data();
- resultCodeData.setId("resultCodeData_"
- +
requestMetadata[i].getId());
-
resultCodeData.setMetadataIdRef("resultCodeMeta_"
- +
requestMetadata[i].getId());
+ }
+ }
- Datum resultCodeDatum = null;
- if (deviceElementOK) {
- resultCodeDatum = new Datum();
-
resultCodeDatum.setId("resultCodeDatum_"
- +
requestMetadata[i].getId());
- resultCodeDatum
-
.setValue("Requested device not supported");
- } else {
- resultCodeDatum = new Datum();
-
resultCodeDatum.setId("resultCodeDatum_"
- +
requestMetadata[i].getId());
- resultCodeDatum
- .setValue("No
Device element given in request");
- }
+ while (!requestMonitor.isCompleted()) {
+ try {
+ //Toolkit toolkit = Toolkit.getDefaultToolkit();
+ //toolkit.beep();
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+
logger.error("[WEBSERVICEENGINEADAPTER][TakeAction]"+e.getStackTrace().toString());
+ }
+ }
-
resultCodeData.addChild(resultCodeDatum);
+ Message[] resultMessages = requestMonitor.getResultMessages();
-
messages[i].setMetadata(resultCodeMetadata);
- messages[i].setData(resultCodeData);
+ for (int i = 0; i < messages.length; i++) {
+ if (messages[i] == null) {
+ messages[i] = resultMessages[i];
+ }
+ }
- requestMonitor.setCompleted(i, null);
+ Message returnMessage = new Message();
+ for (int i = 0; i < messages.length; i++) {
- }
- }
+ for (int j = 0; j < messages[i].getMetadataArray().length;
j++) {
+
returnMessage.setMetadata(messages[i].getMetadataArray()[j]);
+ }
- while (!requestMonitor.isCompleted()) {
- try {
- Toolkit toolkit =
Toolkit.getDefaultToolkit();
- toolkit.beep();
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
+ for (int j = 0; j < messages[i].getDataArray().length; j++) {
+ returnMessage.setData(messages[i].getDataArray()[j]);
+ }
- Message[] resultMessages =
requestMonitor.getResultMessages();
+ }
+
+ for (int i = 0; i<currentDevices.length; i++) {
+ if (currentDevices[i] > -1) {
+ count[currentDevices[i]]--;
+ logger.debug("Concurrent connections for device \"" +
devices.get(i) +
+ "\" decreased by 1; concurrent
connections: "+ count[currentDevices[i]]);
+ }
+ }
+
+ return returnMessage;
- for (int i = 0; i < messages.length; i++) {
- if (messages[i] == null)
- messages[i] = resultMessages[i];
- }
+ }
- Message returnMessage = new Message();
- for (int i = 0; i < messages.length; i++) {
+ // return new ServiceEngineResponse();
- for (int j = 0; j <
messages[i].getMetadataArray().length; j++) {
- returnMessage
-
.setMetadata(messages[i].getMetadataArray()[j]);
- }
+ }
- for (int j = 0; j <
messages[i].getDataArray().length; j++) {
-
returnMessage.setData(messages[i].getDataArray()[j]);
- }
+ private Message createServiceCapabilitiesResponse(Message request) {
- }
+ Message response = new Message();
+ response.setId(request.getId());
+ response.setType("MetadataKeyResponse");
- return returnMessage;
+ Data[] respData;
+ Metadata[] respMetaData;
- }
+ Iterator it = devices.iterator();
+ String token = null;
+ int tokencounter = 0;
+ String innerToken = null;
+ StringTokenizer tokenizer = null;
- // return new ServiceEngineResponse();
+ respMetaData = new Metadata[devices.size()];
+ respData = new Data[devices.size()];
- }
+ Subject subject = null;
+ EventType eventType = null;
+ Datum datum = null;
- private Message createServiceCapabilitiesResponse(Message request) {
+ while (it.hasNext()) {
- Message response = new Message();
- response.setId(request.getId());
- response.setType("MetadataKeyResponse");
+ token = (String) it.next();
- Data[] respData;
- Metadata[] respMetaData;
+ respMetaData[tokencounter] = new Metadata();
+ respMetaData[tokencounter].setId("metadata" + tokencounter);
- Iterator it = devices.iterator();
- String token = null;
- int tokencounter = 0;
- String innerToken = null;
- StringTokenizer tokenizer = null;
+ subject = new Subject();
+ subject.setId("subject" + tokencounter);
+ subject.setSubject(token);
- respMetaData = new Metadata[devices.size()];
- respData = new Data[devices.size()];
+ Parameters metaParams = new Parameters();
+ metaParams.setId("metaParams" + tokencounter);
- Subject subject = null;
- EventType eventType = null;
- Datum datum = null;
+ Parameter metaparam = new Parameter();
+ metaparam.setParameterName("url");
+ try {
+ metaparam.setParameterValue(configuration.getProperty(token,
"url"));
+ } catch (PerfSONARException e1) {
+
logger.error("[WEBSERVICEENGINEADAPTER][CreateServiceCapabilitiesResponse]"+e1.getStackTrace().toString());
+ }
- while (it.hasNext()) {
+ metaParams.addChild(metaparam);
- token = (String) it.next();
+ respMetaData[tokencounter].addChild(subject);
+ respMetaData[tokencounter].addChild(metaParams);
- respMetaData[tokencounter] = new Metadata();
- respMetaData[tokencounter].setId("metadata" +
tokencounter);
+ try {
- subject = new Subject();
- subject.setId("subject" + tokencounter);
- subject.setSubject(token);
+ //re-write this to ArrayList
- Parameters metaParams = new Parameters();
- metaParams.setId("metaParams" + tokencounter);
+ Iterator commands = configuration.getProperties(token,
"commands").iterator();
+ respData[tokencounter] = new Data();
+ respData[tokencounter].setId("data" + tokencounter);
+
respData[tokencounter].setMetadataIdRef(respMetaData[tokencounter].getId());
- Parameter metaparam = new Parameter();
- metaparam.setParameterName("url");
- try {
- metaparam.setParameterValue(properties
- .getProperty("service.r.mp."
+ token + ".url"));
- } catch (PerfSONARException e1) {
- e1.printStackTrace();
- }
+ while (commands.hasNext()) {
- metaParams.addChild(metaparam);
+ innerToken = (String) commands.next();
- respMetaData[tokencounter].addChild(subject);
- respMetaData[tokencounter].addChild(metaParams);
+ datum = new Datum();
- try {
+ eventType = new EventType();
+ eventType.addText(innerToken);
+ logger.debug(innerToken);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." +
token + ".commands"), ",");
- respData[tokencounter] = new Data();
- respData[tokencounter].setId("data" +
tokencounter);
- respData[tokencounter]
-
.setMetadataIdRef(respMetaData[tokencounter].getId());
+ Parameters params = new Parameters();
+ params.setId("params" + tokencounter);
- while (tokenizer.hasMoreTokens()) {
+ Parameter param1 = new Parameter();
+ try {
+ param1.setId("param1-" + tokencounter);
+ param1.setParameterName("description");
+
param1.setParameterValue(configuration.getProperty(token, innerToken,
"description"));
+ } catch (PerfSONARException e) {
+
logger.error("[WEBSERVICEENGINEADAPTER][CreateServiceCapabilitiesResponse]"+e.getStackTrace()[0].toString());
+ }
- innerToken = tokenizer.nextToken();
+ Parameter param2 = new Parameter();
+ try {
+ param2.setId("param2-" + tokencounter);
+ param2.setParameterName("syntax");
+
param2.setParameterValue(configuration.getProperty(token, innerToken,
"syntax"));
+ } catch (PerfSONARException e) {
+
logger.error("[WEBSERVICEENGINEADAPTER][CreateServiceCapabilitiesResponse]"+e.getStackTrace()[0].toString());
+ }
- datum = new Datum();
+ Parameter param3 = new Parameter();
+ try {
+ param3.setId("param3-" + tokencounter);
+ param3.setParameterName("command");
+
param3.setParameterValue(configuration.getProperty(token, innerToken,
"command"));
+ } catch (PerfSONARException e) {
+
logger.error("[WEBSERVICEENGINEADAPTER][CreateServiceCapabilitiesResponse]"+e.getStackTrace()[0].toString());
+ }
- eventType = new EventType();
- eventType.addText(innerToken);
- // System.out.println(innerToken);
+ params.addChild(param1);
+ params.addChild(param2);
+ params.addChild(param3);
- Parameters params = new Parameters();
- params.setId("params" + tokencounter);
+ datum.addChild(eventType);
+ datum.addChild(params);
- Parameter param1 = new Parameter();
- try {
- param1.setId("param1-" +
tokencounter);
-
param1.setParameterName("description");
-
param1.setParameterValue(properties
-
.getProperty("service.mp." + token
-
+ ".commands." + innerToken
-
+ ".description"));
- } catch (PerfSONARException e) {
- }
+ respData[tokencounter].addChild(datum);
- Parameter param2 = new Parameter();
- try {
- param2.setId("param2-" +
tokencounter);
-
param2.setParameterName("syntax");
- param2
-
.setParameterValue(properties
-
.getProperty("service.mp." + token
-
+ ".commands." + innerToken
-
+ ".syntax"));
- } catch (PerfSONARException e) {
- }
+ // Result Code stuff
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
tokencounter);
- Parameter param3 = new Parameter();
- try {
- param3.setId("param3-" +
tokencounter);
-
param3.setParameterName("command");
-
param3.setParameterValue(properties
-
.getProperty("service.mp." + token
-
+ ".commands." + innerToken));
- } catch (PerfSONARException e) {
- }
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
tokencounter);
+ resultCodeSubject.setMetadataIdRef("metadata" +
tokencounter);
- params.addChild(param1);
- params.addChild(param2);
- params.addChild(param3);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
tokencounter);
+ resultCodeEventType.setEventType("success.mp.sshtelnet");
- datum.addChild(eventType);
- datum.addChild(params);
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);
-
respData[tokencounter].addChild(datum);
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" + tokencounter);
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
tokencounter);
- // Result Code stuff
- Metadata resultCodeMetadata = new
Metadata();
-
resultCodeMetadata.setId("resultCodeMeta_" + tokencounter);
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" + tokencounter);
+ resultCodeDatum.setValue("Successfully executed
MetaDataKeyRequest");
- Subject resultCodeSubject = new
Subject();
-
resultCodeSubject.setId("resultCodeSubj_" + tokencounter);
-
resultCodeSubject.setMetadataIdRef("metadata"
- + tokencounter);
+ resultCodeData.addChild(resultCodeDatum);
- EventType resultCodeEventType = new
EventType();
-
resultCodeEventType.setId("resultCodeEventType_"
- + tokencounter);
-
resultCodeEventType.setEventType("success.mp.sshtelnet");
+ response.setMetadata(resultCodeMetadata);
+ response.setData(resultCodeData);
-
resultCodeMetadata.addChild(resultCodeSubject);
-
resultCodeMetadata.addChild(resultCodeEventType);
+ }
- Data resultCodeData = new Data();
-
resultCodeData.setId("resultCodeData_" + tokencounter);
-
resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + tokencounter);
+ } catch (PerfSONARException e) {
- Datum resultCodeDatum = new Datum();
-
resultCodeDatum.setId("resultCodeDatum_" + tokencounter);
- resultCodeDatum
-
.setValue("Successfully executed MetaDataKeyRequest");
+ // Result Code stuff
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" + tokencounter);
-
resultCodeData.addChild(resultCodeDatum);
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" + tokencounter);
+ resultCodeSubject.setMetadataIdRef("metadata" +
tokencounter);
-
response.setMetadata(resultCodeMetadata);
- response.setData(resultCodeData);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
tokencounter);
+ resultCodeEventType.setEventType("success.mp.sshtelnet");
- }
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);
- } catch (PerfSONARException e) {
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" + tokencounter);
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
tokencounter);
- // Result Code stuff
- Metadata resultCodeMetadata = new Metadata();
- resultCodeMetadata.setId("resultCodeMeta_" +
tokencounter);
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" + tokencounter);
+ resultCodeDatum.setValue("Successfully executed
MetaDataKeyRequest");
- Subject resultCodeSubject = new Subject();
- resultCodeSubject.setId("resultCodeSubj_" +
tokencounter);
- resultCodeSubject.setMetadataIdRef("metadata"
+ tokencounter);
+ resultCodeData.addChild(resultCodeDatum);
- EventType resultCodeEventType = new
EventType();
- resultCodeEventType
- .setId("resultCodeEventType_"
+ tokencounter);
-
resultCodeEventType.setEventType("success.mp.sshtelnet");
+ response.setMetadata(resultCodeMetadata);
+ response.setData(resultCodeData);
-
resultCodeMetadata.addChild(resultCodeSubject);
-
resultCodeMetadata.addChild(resultCodeEventType);
+ }
- Data resultCodeData = new Data();
- resultCodeData.setId("resultCodeData_" +
tokencounter);
-
resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + tokencounter);
+ response.setMetadata(respMetaData[tokencounter]);
+ response.setData(respData[tokencounter]);
+ tokencounter++;
- Datum resultCodeDatum = new Datum();
- resultCodeDatum.setId("resultCodeDatum_" +
tokencounter);
- resultCodeDatum
- .setValue("Successfully
executed MetaDataKeyRequest");
+ }
- resultCodeData.addChild(resultCodeDatum);
+ return response;
- response.setMetadata(resultCodeMetadata);
- response.setData(resultCodeData);
+ }
- }
+ private void registerServiceWithLS() {
+ /**
+ * try { ServiceLSRegistrator registrator = new
+ * GenericServiceLSRegistrator (new PropertiesServiceDescription(),
+ * null);
+ *
+ * registrator.initRegistrator();
+ *
+ * Message responseMessage =
+ *
registrator.register("http://chaos4.test:8080/axis/services/LookupService");
+ * System.out.println(responseMessage); } catch (PerfSONARException e) {
//
+ * TODO Auto-generated catch block e.printStackTrace(); }
+ */
+ }
- response.setMetadata(respMetaData[tokencounter]);
- response.setData(respData[tokencounter]);
- tokencounter++;
+ // THREAD TESTING PURPOSES
+ public class SimpleThread extends Thread {
- }
+ public SimpleThread(String str) {
+ super(str);
+ }
- return response;
+ public void run() {
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ for (int i = 0; i < 10; i++) {
+ toolkit.beep();
+ try {
+ sleep((long) (Math.random() * 1000));
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
- }
-
- private void registerServiceWithLS() {
- /**
- * try { ServiceLSRegistrator registrator = new
- * GenericServiceLSRegistrator (new
PropertiesServiceDescription(),
- * null);
- *
- * registrator.initRegistrator();
- *
- * Message responseMessage =
- *
registrator.register("http://chaos4.test:8080/axis/services/LookupService");
- * System.out.println(responseMessage); } catch
(PerfSONARException e) { //
- * TODO Auto-generated catch block e.printStackTrace(); }
- */
- }
-
- // THREAD TESTING PURPOSES
- public class SimpleThread extends Thread {
- public SimpleThread(String str) {
- super(str);
- }
-
- public void run() {
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- for (int i = 0; i < 10; i++) {
- toolkit.beep();
- try {
- sleep((long) (Math.random() * 1000));
- } catch (InterruptedException e) {
- }
- }
- }
- }
-
- public static void main(String[] args) {
- /**
- * try { new WebserviceEngineAdapter().new
- * SimpleThread("Jamaica").start(); new
WebserviceEngineAdapter().new
- * SimpleThread("Fiji").start(); } catch (SystemException e)
{ // TODO
- * Auto-generated catch block e.printStackTrace(); }
- */
-
- try {
- WebserviceEngineAdapter adapter = new
WebserviceEngineAdapter();
- } catch (PerfSONARException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ public static void main(String[] args) {
+ /**
+ * try { new WebserviceEngineAdapter().new
+ * SimpleThread("Jamaica").start(); new WebserviceEngineAdapter().new
+ * SimpleThread("Fiji").start(); } catch (SystemException e) { //
TODO
+ * Auto-generated catch block e.printStackTrace(); }
+ */
+ try {
+ WebserviceEngineAdapter adapter = new WebserviceEngineAdapter();
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
+
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -8,8 +8,8 @@
/**
- * Implementation class that supports querying the device (Quagga) for
- * ip information
+ * Implementation class that supports querying the device for
+ * information
*
* TODO::Correct error classes TODO::Parse output ??
*
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,7 +1,7 @@
/*
- * Created/Updated on May 9th, 2006
- * Version Number: 0.2
- * Project: perfSonar
+ * Created/Updated on January 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands;
@@ -10,10 +10,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
-import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
+import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
/**
* Provides functionality for basic paramter input checking
@@ -22,81 +22,78 @@
*
*/
public class ParameterChecker implements ParameterCheckerInterface {
-
- private PropertiesConfigurationComponent properties = new
PropertiesConfigurationComponent();
- /**
- * Global method for checking the validity of the of inputted
parameters,
- * according to the given requestType
- *
- * @param eventTypeString
- * @param parameter
- * @return boolean
- */
- public boolean checkParam(String subject, String eventTypeString,
- String parameter) {
-
-
+ private MetadataConfiguration properties;
+ private LoggerComponent logger = null;
- try {
- Class c =
Class.forName("org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands."+subject+"Checker");
- return
((Boolean)c.getDeclaredMethods()[0].invoke(c.newInstance(), new Object[]
{subject, eventTypeString, parameter})).booleanValue();
- } catch (ClassNotFoundException e) {
- } catch (IllegalArgumentException e) {
- } catch (SecurityException e) {
- } catch (IllegalAccessException e) {
- } catch (InvocationTargetException e) {
- } catch (InstantiationException e) {
- }
-
- // Bekijk hier in de configfile of er een reguliere
expressielijst
- // bestaat om tbe parameters te checken.
-
- boolean ok = false;
- try {
- properties =
(PropertiesConfigurationComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.CONFIG);
-
- String regularExpressions =
properties.getProperty("service.mp."+subject+".commands."+eventTypeString+".regex");
- System.out.println("Regular Expressions for command "
+ eventTypeString + ": "+regularExpressions);
- StringTokenizer disjunct = new
StringTokenizer(regularExpressions, "#");
+ /**
+ * Global method for checking the validity of the of inputted parameters,
+ * according to the given requestType
+ *
+ * @param eventTypeString
+ * @param parameter
+ * @return boolean
+ */
+ public boolean checkParam(String subject, String eventTypeString,
+ String parameter) {
- while (disjunct.hasMoreTokens() && !ok) {
-
- String disjunctToken = disjunct.nextToken();
- StringTokenizer tokenizer = new
StringTokenizer (disjunctToken, ";"); // get property
-
- ok = true;
- while (tokenizer.hasMoreTokens() && ok) {
- String token = tokenizer.nextToken();
-
- System.out.println("pattern: " +
token);
- System.out.println("parameter: " +
parameter);
-
- Pattern pattern =
Pattern.compile(token);
- Matcher matcher =
pattern.matcher(parameter);
- ok = matcher.find();
- System.out.println("OK: " + ok);
- }
- }
- } catch (PerfSONARException e1) {
- e1.printStackTrace();
- }
+ try {
+ Class c =
Class.forName("org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands."
+ subject + "Checker");
+ return ((Boolean)
c.getDeclaredMethods()[0].invoke(c.newInstance(), new Object[]{subject,
eventTypeString, parameter})).booleanValue();
+ } catch (ClassNotFoundException e) {
+ } catch (IllegalArgumentException e) {
+ } catch (SecurityException e) {
+ } catch (IllegalAccessException e) {
+ } catch (InvocationTargetException e) {
+ } catch (InstantiationException e) {
+ }
- return ok;
- }
-
-
- /**
- * Test-purposes
- *
- * @param argv
- */
- public static void main(String[] argv) {
+ // Bekijk hier in de configfile of er een reguliere expressielijst
+ // bestaat om tbe parameters te checken.
- ParameterChecker checker = new ParameterChecker();
- System.out.println(checker.checkParam("juniper1",
"BGP_PEERING_STATUS",
- "157.193.214.0/24"));
- }
+ boolean ok = false;
+ try {
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
+ String regularExpressions = properties.getProperty(subject,
eventTypeString, "regex");
+ //System.out.println("Regular Expressions for command " +
eventTypeString + ": " + regularExpressions);
+ StringTokenizer disjunct = new
StringTokenizer(regularExpressions, "#");
+
+ while (disjunct.hasMoreTokens() && !ok) {
+
+ String disjunctToken = disjunct.nextToken();
+ StringTokenizer tokenizer = new
StringTokenizer(disjunctToken, ";"); // get property
+
+ ok = true;
+ while (tokenizer.hasMoreTokens() && ok) {
+ String token = tokenizer.nextToken();
+
+ //System.out.println("pattern: " + token);
+ //System.out.println("parameter: " + parameter);
+
+ Pattern pattern = Pattern.compile(token);
+ Matcher matcher = pattern.matcher(parameter);
+ ok = matcher.find();
+ //System.out.println("OK: " + ok);
+ }
+ }
+ } catch (PerfSONARException e1) {
+ //e1.printStackTrace();
+ }
+
+ return ok;
+ }
+
+ /**
+ * Test-purposes
+ *
+ * @param argv
+ */
+ public static void main(String[] argv) {
+
+ ParameterChecker checker = new ParameterChecker();
+ //System.out.println(checker.checkParam("juniper1", "BGP_PEERING_STATUS",
+ // "157.193.214.0/24"));
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created on Dec 12, 2005
- * Version Number: 0.1
+ * Created on Jan 8, 2008
+ * Version Number: 1.0
* Project: perfSonar
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip;
@@ -10,7 +10,6 @@
import org.perfsonar.base.exceptions.PerfSONARException;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
-
/**
* Interface to which device ip statistics providers should adhere
*
@@ -20,53 +19,51 @@
*
*/
public interface IpAdapterInterface {
-
- // ---------------------- interface methods
-
- /**
- * Interface method to query about the device specific command
available
- *
- * @return List All specific StatusCommands for the device
- */
- public abstract List getAvailableSpecificCommands() ;
-
- /**
- * Sets the list with all specific commands available for that device
- *
- * @param availableSpecificCommands
- */
- public abstract void setAvailableSpecificCommands(List
availableSpecificCommands) ;
- /**
- * Adds a specific command to the list of available specific commands
- *
- * @param command
- */
- public abstract void addAvailableSpecificCommand(IpCommandInterface
command) ;
-
- /**
- * Searches for a command supported by the device matching the given
- * description
- *
- * @param description
- * @return IpCommandInterface representing the desirec command
- */
- public abstract IpCommandInterface getCommand(String description)
throws PerfSONARException;
-
- /**
- * Executes the provided command on the remote device
- *
- *
- * @param command The IpCommand to be executed command
- * @return IpCommand with the results inserted
- */
- public abstract IpCommandInterface executeCommand(IpCommandInterface
command) ;
-
- /**
- * Makes the Adapter connecting to the device
- *
- */
- public abstract void connect() ;
-
- //List of commands that should be available to all status MP to be
included below
+ // ---------------------- interface methods
+ /**
+ * Interface method to query about the device specific command available
+ *
+ * @return List All specific StatusCommands for the device
+ */
+ public abstract List getAvailableSpecificCommands();
+
+ /**
+ * Sets the list with all specific commands available for that device
+ *
+ * @param availableSpecificCommands
+ */
+ public abstract void setAvailableSpecificCommands(List
availableSpecificCommands);
+
+ /**
+ * Adds a specific command to the list of available specific commands
+ *
+ * @param command
+ */
+ public abstract void addAvailableSpecificCommand(IpCommandInterface
command);
+
+ /**
+ * Searches for a command supported by the device matching the given
+ * description
+ *
+ * @param description
+ * @return IpCommandInterface representing the desirec command
+ */
+ public abstract IpCommandInterface getCommand(String description) throws
PerfSONARException;
+
+ /**
+ * Executes the provided command on the remote device
+ *
+ *
+ * @param command The IpCommand to be executed command
+ * @return IpCommand with the results inserted
+ */
+ public abstract IpCommandInterface executeCommand(IpCommandInterface
command);
+
+ /**
+ * Makes the Adapter connecting to the device
+ *
+ */
+ public abstract void connect();
+ //List of commands that should be available to all status MP to be
included below
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.telnet.TelnetManager;
@@ -44,637 +45,586 @@
*/
public class CiscoIpAdapter implements IpAdapterInterface, ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoIpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoIpAdapter] Constructor finished");
- // ---------------------- constructors
+ }// CiscoIpAdapter
- public CiscoIpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[CiscoIpAdapter] getAvailableSpecificCommands called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoIpAdapter] setAvailableSpecificCommand called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(IpCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoIpAdapter] addAvailableSpecificCommand called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoIpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoIpAdapter
+ logger.debug("[CiscoIpAdapter] getCommand called");
- // ---------------------- public methods
+ IpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[CiscoIpAdapter] getAvailableSpecificCommands
called");
+ command = (IpCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoIpAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[CiscoIpAdapter] setAvailableSpecificCommand
called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoIpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface executeCommand(IpCommandInterface command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(IpCommandInterface command) {
+ logger.debug("[CiscoIpAdapter] executeCommand called");
- logger.debug("[CiscoIpAdapter] addAvailableSpecificCommand
called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");
+ //logger.debug("temp2: " + temp2);
- }// addAvailableSpecificCommand
+ manager.disconnect();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ command.setResult(temp2);
- logger.debug("[CiscoIpAdapter] getCommand called");
+ command.setTimestamp(System.currentTimeMillis());
- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// if
- while (it.hasNext()) {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoIpAdapter] executeCommand finished");
+ return command;
- command = (IpCommand) it.next();
+ }// executeCommand
+ public void connect() {
+ }
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- logger.debug("[CiscoIpAdapter] Command
found");
- return command;
+ logger.debug("[CiscoIpAdapter] Connect called");
- }
+ try {
- }// while
+ if (manager == null) {
- logger.error("[CiscoIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ try {
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ if (username.equals("") || password.equals("")) {
+ throw new
PerfSONARException("error.mp.sshtelnet.configuration",
+ "Username or password not set");
+ }
+ } catch (Exception e) {
+ logger.error("[CiscoIpAdapter] Error in configuration");
+ logger.error("[CISCOIPADAPTER][Connect]" +
e.getStackTrace().toString());
+ throw e;
+ }
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// getCommand
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ }
- logger.debug("[CiscoIpAdapter] executeCommand called");
+ logger.debug("[CiscoIpAdapter] Trying to connect");
- if (manager != null) {
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
- // System.err.println("temp2: " + temp2);
+ logger.debug("[CiscoIpv6Adapter Login");
- manager.disconnect();
+ } catch (Exception e) {
- command.setResult(temp2);
-
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[CiscoIpAdapter] Error occuring while connecting");
+ logger.error("[CISCOIPADAPTER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoIpAdapter] executeCommand finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.debug("[CiscoIpAdapter] Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- if (username.equals("") ||
password.equals(""))
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Username or
password not set");
- } catch (Exception e) {
- logger.error("[CiscoIpAdapter] Error
in configuration");
-
logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public String getPrompt() {
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ return prompt;
- }
+ }
- logger.debug("[CiscoIpAdapter] Trying to connect");
+ public void setPrompt(String prompt) {
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;
- logger.debug("[CiscoIpv6Adapter Login");
+ }
- } catch (Exception e) {
+ public String getUrl() {
- logger.error("[CiscoIpAdapter] Error occuring while
connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ return url;
- }
+ }
- }// connect
+ public void setUrl(String url) {
- // ---------------------- field methods
+ this.url = url;
- public int getPort() {
+ }
- return port;
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- }
+ logger.debug("[CiscoIpAdapter] Configuring available operations
...");
- public void setPort(int port) {
+ Iterator commands = null;
+ String token = null;
- this.port = port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public String getPrompt() {
+ token = (String) commands.next();
+ if (token.contains("IP_")) {
- return prompt;
+ IpCommand command = new IpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+ logger.error("[CISCOIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+ logger.error("[CISCOIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public String getUrl() {
+ logger.error("[CISCOIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- return url;
+ }
- }
+ // this.addAvailableSpecificCommand(new
+ // IpCommand(ActionType.MP_IP_FORWARDING, "show ip forwarding"));
+ // this.addAvailableSpecificCommand(new
+ // IpCommand(ActionType.MP_IP_ROUTE, "show ip route"));
+ // this.addAvailableSpecificCommand(new
+ // IpCommand(ActionType.MP_IP_ROUTESUPERNETS, "show ip route
+ // supernets-only"));
- public void setUrl(String url) {
+ logger.debug("[CiscoIpAdapter] Available operations configured");
- this.url = url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, IpCommandInterface ipCommand) {
- // ---------------------- Private methods
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- logger.debug("[CiscoIpAdapter] Configuring available
operations ...");
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ String tempResult = temp.substring((ipCommand.getCommand() + " " +
ipCommand.getParameterString()).length());
- try {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- token = tokenizer.nextToken();
- if (token.contains("IP_")) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- IpCommand command = new
IpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- } catch (PerfSONARException e) {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ return this.serviceEngineType;
- }
+ }
- // this.addAvailableSpecificCommand(new
- // IpCommand(ActionType.MP_IP_FORWARDING, "show ip
forwarding"));
- // this.addAvailableSpecificCommand(new
- // IpCommand(ActionType.MP_IP_ROUTE, "show ip route"));
- // this.addAvailableSpecificCommand(new
- // IpCommand(ActionType.MP_IP_ROUTESUPERNETS, "show ip route
- // supernets-only"));
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- logger.debug("[CiscoIpAdapter] Available operations
configured");
+ logger.info("[CiscoIpAdapter] Webservice takeAction call received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, IpCommandInterface
ipCommand) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("SUBJECTSTRING: " + subject);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- }
- String tempResult = temp
- .substring((ipCommand.getCommand() + " " +
ipCommand
-
.getParameterString()).length());
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ CiscoIpAdapter adapter = new CiscoIpAdapter();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ // REPLACED
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ availableSpecificCommands = new ArrayList();
- t2 = resultBuffer.toString();
+ try {
- return t2.replace("" + prompt, "---END---");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ manager = new TelnetManager(url, port, false, timeout);
- // ---------------------- Methods from service engine interface
+ } catch (NumberFormatException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[CISCOIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return this.serviceEngineType;
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[CISCOIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve url");
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ }
- logger.info("[CiscoIpAdapter] Webservice takeAction call
received");
+ logger.debug("[CiscoStatusAdapter] TelnetManager created: " + url +
" " + port);
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ try {
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ } catch (PerfSONARException e) {
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ logger.error("[CISCOIPADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ }
- CiscoIpAdapter adapter = new CiscoIpAdapter();
- //adapter.connect(subject);
+ logger.debug("[CiscoStatusAdapter] Prompt set in TelnetManager: " +
prompt);
- // REPLACED
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- availableSpecificCommands = new ArrayList();
+ //
- try {
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- manager = new TelnetManager(url, port, false);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- } catch (NumberFormatException e1) {
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve url");
+ if (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {
- }
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- logger.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- try {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- } catch (PerfSONARException e) {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- logger.debug("[CiscoStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ }
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ if (temp.equalsIgnoreCase("")) {
- //
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipCommand).getResult();
- IpCommandInterface ipCommand =
this.getCommand(eventTypeString);
+ }
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ } else if (ipCommand.getMinParamCount() == 0) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- }
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (ipCommand.getParameters().size() >= ipCommand
- .getMinParamCount()
- && ipCommand.getParameters().size()
<= ipCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } else if (ipCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipCommand).getResult();
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ } else {
- logger.info("[CiscoIpAdapter] Command executed succesfully");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ }
- logger.info("[CiscoIpAdapter] Constructing response message");
+ logger.info("[CiscoIpAdapter] Command executed succesfully");
- Message response = new Message();
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- for (int i = 0; i < request.getMetadataArray().length; i++)
- response.setMetadata(respMetaData[i]);
- response.setData(respData[0]);
+ logger.info("[CiscoIpAdapter] Constructing response message");
- // System.err.println(respMetaData);
- // System.err.println(respData);
+ Message response = new Message();
- // response.setSonarMetadata(request.getSonarMetadata());
- // response.setSonarData(new Data[] { data });
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ for (int i = 0; i < request.getMetadataArray().length; i++) {
+ response.setMetadata(respMetaData[i]);
+ }
+ response.setData(respData[0]);
- logger.info("[CiscoIpAdapter] takeAction finished");
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");
- return response;
- // return new ServiceEngineResponse();
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });
- }
+ logger.info("[CiscoIpAdapter] takeAction finished");
- // ---------------------- Stand-alond Test Method
+ return response;
+ // return new ServiceEngineResponse();
- public static void main(String[] args) {
+ }
- try {
- CiscoIpAdapter adapter = new CiscoIpAdapter();
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("cisco1");
+ try {
+ CiscoIpAdapter adapter = new CiscoIpAdapter();
- adapter.connect("cisco1");
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("cisco1");
- IpCommandInterface ipCommand;
+ adapter.connect("cisco1");
- try {
+ IpCommandInterface ipCommand;
- ipCommand = adapter.getCommand("IP_ROUTE");
- String temp =
adapter.executeCommand(ipCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- System.out.println(temp);
+ try {
- } catch (PerfSONARException e) {
+ ipCommand = adapter.getCommand("IP_ROUTE");
+ String temp = adapter.executeCommand(ipCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- e.printStackTrace();
+ } catch (PerfSONARException e) {
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ //e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters;
@@ -21,15 +21,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshKeyManager;
@@ -66,6 +68,8 @@
private String passphrase = "";
private int caching = 0;
+
+ private int timeout = 0;
// ---------------------- class-fields
@@ -75,7 +79,7 @@
private LoggerComponent logger = null;
- private PropertiesConfigurationComponent properties = null;
+ private MetadataConfiguration properties = null;
// ---------------------- caching attributes
@@ -90,8 +94,8 @@
logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
.getComponent(ComponentNames.LOGGER);
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
@@ -100,7 +104,7 @@
} catch (PerfSONARException e) {
- e.printStackTrace();
+
logger.error("[CISCOKEYIPADAPTER][Constructor]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Failed to obtain reference to the
properties and/or logger instances.");
@@ -187,7 +191,7 @@
if (manager != null) {
- System.out.println("Executing command");
+ logger.debug("Executing command");
String temp2 =
manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
@@ -218,18 +222,13 @@
if (manager == null) {
url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
+ .getProperty(subject, "url");
+ port =
Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject,
"prompt");
try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
+ username =
properties.getProperty(subject, "username");
+ keyUrl =
properties.getProperty(subject, "keyUrl");
+ passphrase =
properties.getProperty(subject, "passphrase");
if (username.equals("") ||
keyUrl.equals(""))
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Username or
KeyURL not set");
@@ -238,24 +237,25 @@
logger.error(e.getStackTrace().toString());
throw e;
}
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ timeout =
Integer.parseInt(properties.getProperty(subject, "timeout"));
- manager = new SshKeyManager(url, username,
keyUrl, false);
-
+ if (passphrase == null ||
passphrase.equals("")) {
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ } else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+
}
logger.info("[CiscoKeyIpAdapter] Trying to connect");
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //if (passphrase == null || passphrase.equals(""))
+ //manager.connect(username, keyUrl);
+ //else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
logger.info("[CiscoKeyIpAdapter] Login");
} catch (Exception e) {
- logger
- .error("[CiscoKeyIpAdapter] Error
occuring while connecting");
+ logger.error("[CiscoKeyIpAdapter] Error occuring
while connecting");
logger.error(e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.connect",
"Could not connect to underlying
device");
@@ -313,36 +313,32 @@
logger
.debug("[CiscoKeyIpAdapter] Configuring
available operations ...");
- StringTokenizer tokenizer = null;
+ Iterator commands = null;
String token = null;
try {
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- token = tokenizer.nextToken();
+ token = (String) commands.next();
if (token.contains("IP_")) {
IpCommand command = new
IpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
+ .getProperty(subject,
token, "command"));
try {
int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
+
.getProperty(subject, token, "minParamCount"));
command.setMinParamCount(minParamCount);
} catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYIPADAPTER][ConfigureCommands]"+e1.getStackTrace().toString());
}
try {
int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
+
.getProperty(subject, token, "maxParamCount"));
command.setMaxParamCount(maxParamCount);
} catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYIPADAPTER][ConfigureCommands]"+e1.getStackTrace().toString());
}
command.setDeviceName(subject);
@@ -354,7 +350,7 @@
} catch (PerfSONARException e) {
- e.printStackTrace();
+
logger.error("[CISCOKEYIPADAPTER][ConfigureCommands]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Unable to retrieve commands");
@@ -388,9 +384,9 @@
.getParameterString()).length());
String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
+ logger.debug(t1);
String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ logger.debug(t2);
StringBuffer resultBuffer = new StringBuffer(t2);
@@ -431,29 +427,27 @@
EndPoint endpoint = (EndPoint) s.getChildArray()[0];
String subject = endpoint.getValue();
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subject);
EventType eventType = metadata[0].getEventType();
String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- CiscoKeyIpAdapter adapter = new CiscoKeyIpAdapter();
+ //CiscoKeyIpAdapter adapter = new CiscoKeyIpAdapter();
+
//adapter.connect(subject);
availableSpecificCommands = new ArrayList();
try {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
+ url = properties.getProperty(subject, "url");
+ port =
Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
+ username = properties.getProperty(subject,
"username");
+ keyUrl = properties.getProperty(subject,
"keyUrl");
if (username.equals("") || keyUrl.equals(""))
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Username or KeyURL
not set");
@@ -462,21 +456,21 @@
logger.error(e.getStackTrace().toString());
throw e;
}
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ timeout =
Integer.parseInt(properties.getProperty(subject, "timeout"));
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
} catch (NumberFormatException e1) {
- e1.printStackTrace();
+
logger.error("[CISCOKEYIPADAPTER][TakeAction]"+e1.getStackTrace().toString());
throw new PerfSONARException(
"error.mp.sshtelnet.configuration",
"Invalid port number in
configuration");
} catch (PerfSONARException e1) {
- e1.printStackTrace();
+
logger.error("[CISCOKEYIPADAPTER][TakeAction]"+e1.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Unable to retrieve connection
details");
@@ -500,7 +494,7 @@
Parameter param = parametersArray[i];
String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.debug("PARAMETERVALUE: " + parameter);
if (new
ParameterChecker().checkParam(subject, eventTypeString,
parameter)) {
@@ -544,8 +538,8 @@
if (temp.equalsIgnoreCase("")) {
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
+ this.connect(subject);
+ temp =
this.executeCommand(ipCommand).getResult();
}
@@ -583,8 +577,8 @@
if (temp.equalsIgnoreCase("")) {
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
+ this.connect(subject);
+ temp =
this.executeCommand(ipCommand).getResult();
}
@@ -647,15 +641,15 @@
((LoggerComponent)
AuxiliaryComponentManager.getInstance()
.getComponent(ComponentNames.LOGGER)).info(temp);
- System.out.println(adapter.filterResult(temp,
ipCommand));
+
//System.out.println(adapter.filterResult(temp, ipCommand));
} catch (PerfSONARException e) {
- e.printStackTrace();
+ //e.printStackTrace();
}
} catch (PerfSONARException e) {
- e.printStackTrace();
+ //e.printStackTrace();
}
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshManager;
@@ -44,605 +45,554 @@
*/
public class CiscoSshIpAdapter implements IpAdapterInterface, ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoSshIpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOSSHIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoSshIpAdapter] Constructor started");
- // ---------------------- constructors
+ logger.debug("[CiscoSshIpAdapter] Constructor finished");
- public CiscoSshIpAdapter() throws PerfSONARException {
+ }// CiscoSshIpAdapter
- try {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.debug("[CiscoSshIpAdapter] getAvailableSpecificCommands
called");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return availableSpecificCommands;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoSshIpAdapter] setAvailableSpecificCommand
called");
- } catch (PerfSONARException e) {
+ this.availableSpecificCommands = availableSpecificCommands;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(IpCommandInterface command) {
- }
+ logger.debug("[CiscoSshIpAdapter] addAvailableSpecificCommand
called");
- logger.debug("[CiscoSshIpAdapter] Constructor started");
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoSshIpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoSshIpAdapter
+ logger.debug("[CiscoSshIpAdapter] getCommand called");
- // ---------------------- public methods
+ IpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[CiscoSshIpAdapter]
getAvailableSpecificCommands called");
+ command = (IpCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoSshIpAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[CiscoSshIpAdapter] setAvailableSpecificCommand
called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoSshIpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface executeCommand(IpCommandInterface command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(IpCommandInterface command) {
+ logger.debug("[CiscoSshIpAdapter] executeCommand called");
- logger.debug("[CiscoSshIpAdapter] addAvailableSpecificCommand
called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- }// addAvailableSpecificCommand
+ }// if
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshIpAdapter] executeCommand finished");
+ return command;
- logger.debug("[CiscoSshIpAdapter] getCommand called");
+ }// executeCommand
+ public void connect() {
+ }
- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- while (it.hasNext()) {
+ logger.info("[CiscoSshIpAdapter] Connect called");
- command = (IpCommand) it.next();
+ try {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {
- logger.debug("[CiscoSshIpAdapter] Command
found");
- return command;
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ try {
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ if (username.equals("") || password.equals("")) {
+ throw new
PerfSONARException("error.mp.sshtelnet.configuration",
+ "Username or password not set");
+ }
+ } catch (Exception e) {
+ logger.error("[CiscoSshIpAdapter] Error in
configuration");
+ logger.error(e.getStackTrace().toString());
+ throw e;
+ }
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ //System.out.println(username);
+ //System.out.println(password);
- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
+ }
- logger.error("[CiscoSshIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[CiscoSshIpAdapter] Trying to connect");
- }// getCommand
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ logger.info("[CiscoSshIpAdapter Login");
- logger.debug("[CiscoSshIpAdapter] executeCommand called");
+ } catch (Exception e) {
- if (manager != null) {
+ logger.error("[CiscoSshIpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }
- }// if
+ }// connect
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshIpAdapter] executeCommand finished");
- return command;
+ // ---------------------- field methods
+ public int getPort() {
- }// executeCommand
+ return port;
- public void connect() {
- }
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public void setPort(int port) {
- logger.info("[CiscoSshIpAdapter] Connect called");
+ this.port = port;
- try {
+ }
- if (manager == null) {
+ public String getPrompt() {
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- if (username.equals("") ||
password.equals(""))
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Username or
password not set");
- } catch (Exception e) {
- logger.error("[CiscoSshIpAdapter]
Error in configuration");
-
logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ return prompt;
- //System.out.println(username);
- //System.out.println(password);
+ }
- manager = new SshManager(url, username,
password, false);
+ public void setPrompt(String prompt) {
- }
+ this.prompt = prompt;
- logger.info("[CiscoSshIpAdapter] Trying to connect");
+ }
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ public String getUrl() {
- logger.info("[CiscoSshIpAdapter Login");
+ return url;
- } catch (Exception e) {
+ }
- logger.error("[CiscoSshIpAdapter] Error occuring
while connecting");
- //System.err.println("[CiscoSshIpAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[CiscoSshIpAdapter] Configuring available operations
...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("IP")) {
- }
+ IpCommand command = new IpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+ logger.error("[CISCOSSHIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ logger.debug("[CiscoSshIpAdapter] Available operations configured");
- return url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, IpCommandInterface ipCommand) {
- public void setUrl(String url) {
+ //logger.debug("result: " + temp);
+
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- this.url = url;
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- }
+ }
- // ---------------------- Private methods
+ //String tempResult = temp.substring((ipCommand.getCommand() + " "
+ ipCommand.getParameterString()).length());
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ String t1 = temp.replaceAll("\\n", "");
+ String t2 = t1.replaceAll("\\r", "@@@");
- logger.debug("[CiscoSshIpAdapter] Configuring available
operations ...");
+ StringBuffer resultBuffer = new StringBuffer(t2);
- StringTokenizer tokenizer = null;
- String token = null;
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- try {
+ t2 = resultBuffer.toString();
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ return t2.replace("" + prompt, "---END---");
- token = tokenizer.nextToken();
- if (token.contains("IP")) {
+ }
- IpCommand command = new
IpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- }
+ }
- } catch (PerfSONARException e) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ logger.info("[CiscoSshIpAdapter] Webservice takeAction call
received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- logger.debug("[CiscoSshIpAdapter] Available operations
configured");
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, IpCommandInterface
ipCommand) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ //CiscoSshIpAdapter adapter = new CiscoSshIpAdapter();
- String tempResult = temp;
-// .substring((ipCommand.getCommand() + " " +
ipCommand
-//
.getParameterString()).length());
+ // REPLACED
- String t1 = tempResult.replaceAll("\\n", "");
- String t2 = t1.replaceAll("\\r", "@@@");
+ availableSpecificCommands = new ArrayList();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ try {
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
-
- t2 = resultBuffer.toString();
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
- return t2.replace("" + prompt, "---END---");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
+
+ } catch (NumberFormatException e1) {
- }
+ logger.error("[CISCOSSHIPADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- // ---------------------- Methods from service engine interface
+ } catch (PerfSONARException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[CISCOSSHIPADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- return this.serviceEngineType;
+ }
- }
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException{
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- logger.info("[CiscoSshIpAdapter] Webservice takeAction call
received");
+ //
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- CiscoSshIpAdapter adapter = new CiscoSshIpAdapter();
- //adapter.connect(subject);
+ }
- // REPLACED
+ if (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {
- availableSpecificCommands = new ArrayList();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- try {
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- } catch (NumberFormatException e1) {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ }
- }
+ if (temp.equalsIgnoreCase("")) {
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ this.connect(subject);
+ temp = this.executeCommand(ipCommand).getResult();
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ }
- //
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- IpCommandInterface ipCommand =
this.getCommand(eventTypeString);
+ } else if (ipCommand.getMinParamCount() == 0) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (ipCommand.getParameters().size() >= ipCommand
- .getMinParamCount()
- && ipCommand.getParameters().size()
<= ipCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (ipCommand.getMinParamCount() == 0) {
+ if (temp.equalsIgnoreCase("")) {
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ this.connect(subject);
+ temp = this.executeCommand(ipCommand).getResult();
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ }
- } else {
+ } else {
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- }
+ }
- //System.out.println("[CiscoSshIpAdapter] Command executed
succesfully");
- logger.info("[CiscoSshIpAdapter] Command executed
succesfully");
- //System.out.println(valid);
+ logger.info("[CiscoSshIpAdapter] Command executed succesfully");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- //System.out.println("[CiscoSshIpAdapter] Constructing
response message");
- logger.info("[CiscoSshIpAdapter] Constructing response
message");
+ logger.info("[CiscoSshIpAdapter] Constructing response message");
- Message response = new Message();
+ Message response = new Message();
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- logger.info("[CiscoSshIpAdapter] takeAction finished");
+ logger.info("[CiscoSshIpAdapter] takeAction finished");
- return response;
+ return response;
- }
+ }
- // ---------------------- Stand-alond Test Method
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- public static void main(String[] args) {
+ try {
+ CiscoSshIpAdapter adapter = new CiscoSshIpAdapter();
- try {
- CiscoSshIpAdapter adapter = new CiscoSshIpAdapter();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco2");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco2");
+ adapter.connect("cisco2");
- adapter.connect("cisco2");
+ IpCommandInterface ipCommand;
- IpCommandInterface ipCommand;
+ try {
- try {
+ ipCommand = adapter.getCommand("IP_ROUTE");
+ String temp = adapter.executeCommand(ipCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println("Temp: " + temp);
- ipCommand = adapter.getCommand("IP_ROUTE");
- String temp =
adapter.executeCommand(ipCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println("Temp: " + temp);
+ } catch (PerfSONARException e) {
- } catch (PerfSONARException e) {
+ //e.printStackTrace();
- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.telnet.TelnetManager;
@@ -44,635 +45,583 @@
*/
public class JuniperIpAdapter implements IpAdapterInterface, ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
+
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String url = "";
+ // ---------------------- constructors
+ public JuniperIpAdapter() throws PerfSONARException {
- private String prompt = "";
+ try {
- private int port = 0;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String username = "";
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private String password = "";
-
- private int caching = 0;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ } catch (PerfSONARException e) {
- private RemoteManager manager = null;
+ logger.error("[JUNIPERIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private LoggerComponent logger = null;
+ }
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[JuniperIpAdapter] Constructor finished");
- private static List cachedResults = new ArrayList();
+ }// JuniperIpAdapter
- // ---------------------- constructors
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- public JuniperIpAdapter() throws PerfSONARException {
+ logger.debug("[JuniperIpAdapter] getAvailableSpecificCommands
called");
- try {
+ return availableSpecificCommands;
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ logger.debug("[JuniperIpAdapter] setAvailableSpecificCommand
called");
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(IpCommandInterface command) {
- } catch (PerfSONARException e) {
+ logger.debug("[JuniperIpAdapter] addAvailableSpecificCommand
called");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ availableSpecificCommands.add(command);
- }
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- logger.debug("[JuniperIpAdapter] Constructor finished");
+ logger.debug("[JuniperIpAdapter] getCommand called");
- }// JuniperIpAdapter
+ IpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- // ---------------------- public methods
+ while (it.hasNext()) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ command = (IpCommand) it.next();
- logger.debug("[JuniperIpAdapter] getAvailableSpecificCommands
called");
+ if (command.getDescription().equalsIgnoreCase(description)) {
- return availableSpecificCommands;
+ logger.debug("[JuniperIpAdapter] Command found");
+ return command;
- }// getAvailableSpecificCommands
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while
- logger.debug("[JuniperIpAdapter] setAvailableSpecificCommand
called");
+ logger.error("[JuniperIpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- this.availableSpecificCommands = availableSpecificCommands;
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface executeCommand(IpCommandInterface command) {
- }// setAvailableSpecificCommands
+ logger.debug("[JuniperIpAdapter] executeCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(IpCommandInterface command) {
+ if (manager != null) {
- logger.debug("[JuniperIpAdapter] addAvailableSpecificCommand
called");
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");
+ //logger.debug("temp2: " + temp2);
- availableSpecificCommands.add(command);
+ manager.disconnect();
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[JuniperIpAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperIpAdapter] executeCommand finished");
+ return command;
- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (IpCommand) it.next();
+ logger.debug("[JuniperIpAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[JuniperIpAdapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ try {
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ if (username.equals("") || password.equals("")) {
+ throw new
PerfSONARException("error.mp.sshtelnet.configuration",
+ "Username or password not set");
+ }
+ } catch (Exception e) {
+ logger.error("[JuniperIpAdapter] Error in
configuration");
+ logger.error(e.getStackTrace().toString());
+ throw e;
+ }
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- logger.error("[JuniperIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }
- }// getCommand
+ logger.debug("[JuniperIpAdapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[JuniperIpAdapter] executeCommand called");
+ logger.debug("[JuniperIpv6Adapter Login");
- if (manager != null) {
+ } catch (Exception e) {
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
- System.err.println("temp2: " + temp2);
+ logger.error("[JuniperIpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- manager.disconnect();
+ }
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }// connect
- }// if
+ // ---------------------- field methods
+ public int getPort() {
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperIpAdapter] executeCommand finished");
- return command;
+ return port;
- }// executeCommand
+ }
- public void connect() {
- }
+ public void setPort(int port) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;
- logger.debug("[JuniperIpAdapter] Connect called");
+ }
- try {
+ public String getPrompt() {
- if (manager == null) {
+ return prompt;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- if (username.equals("") ||
password.equals(""))
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Username or
password not set");
- } catch (Exception e) {
- logger.error("[JuniperIpAdapter]
Error in configuration");
-
logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ public void setPrompt(String prompt) {
- }
+ this.prompt = prompt;
- logger.debug("[JuniperIpAdapter] Trying to connect");
+ }
- manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ public String getUrl() {
- logger.debug("[JuniperIpv6Adapter Login");
+ return url;
- } catch (Exception e) {
+ }
- logger.error("[JuniperIpAdapter] Error occuring while
connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[JuniperIpAdapter] Configuring available operations
...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("IP_")) {
- }
+ IpCommand command = new IpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+ logger.error("[JUNIPERIPADAPTER][ConfigureCommands]"
+ e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+ logger.error("[JUNIPERIPADAPTER][ConfigureCommands]"
+ e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+ logger.error("[JUNIPERIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ //this.addAvailableSpecificCommand(new
IpCommand(ActionType.MP_IP_FORWARDING, "show ip forwarding"));
+ //this.addAvailableSpecificCommand(new
IpCommand(ActionType.MP_IP_ROUTE, "show ip route"));
+ //this.addAvailableSpecificCommand(new
IpCommand(ActionType.MP_IP_ROUTESUPERNETS, "show ip route supernets-only"));
- return url;
+ logger.debug("[JuniperIpAdapter] Available operations configured");
- }
+ }
- public void setUrl(String url) {
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, IpCommandInterface ipCommand) {
- this.url = url;
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- }
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- // ---------------------- Private methods
+ }
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ while (temp.indexOf("---(more") > 0) {
- logger.debug("[JuniperIpAdapter] Configuring available
operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- StringTokenizer tokenizer = null;
- String token = null;
+ }
- try {
+ String tempResult = temp.substring((ipCommand.getCommand() + " " +
ipCommand.getParameterString()).length());
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- token = tokenizer.nextToken();
- if (token.contains("IP_")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- IpCommand command = new
IpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- //this.addAvailableSpecificCommand(new
IpCommand(ActionType.MP_IP_FORWARDING, "show ip forwarding"));
- //this.addAvailableSpecificCommand(new
IpCommand(ActionType.MP_IP_ROUTE, "show ip route"));
- //this.addAvailableSpecificCommand(new
IpCommand(ActionType.MP_IP_ROUTESUPERNETS, "show ip route supernets-only"));
+ }
- logger.debug("[JuniperIpAdapter] Available operations
configured");
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- }
+ logger.info("[JuniperIpAdapter] Webservice takeAction call
received");
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, IpCommandInterface
ipCommand) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("SUBJECTSTRING: " + subject);
- }
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- while (temp.indexOf("---(more") > 0) {
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ JuniperIpAdapter adapter = new JuniperIpAdapter();
+ //adapter.connect(subject);
- }
+ availableSpecificCommands = new ArrayList();
- String tempResult = temp
- .substring((ipCommand.getCommand() + " " +
ipCommand
-
.getParameterString()).length());
+ try {
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new TelnetManager(url, port, false, timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ } catch (NumberFormatException e1) {
- t2 = resultBuffer.toString();
+ logger.error("[JUNIPERIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return t2.replace("" + prompt, "---END---");
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[JUNIPERIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // ---------------------- Methods from service engine interface
+ }
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.debug("[JuniperIpAdapter] TelnetManager created: " + url + "
" + port);
- return this.serviceEngineType;
+ try {
- }
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ } catch (PerfSONARException e) {
- logger.info("[JuniperIpAdapter] Webservice takeAction call
received");
+ logger.error("[JUNIPERIPADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ }
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ logger.debug("[JuniperIpAdapter] Prompt set in TelnetManager: " +
prompt);
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);
- JuniperIpAdapter adapter = new JuniperIpAdapter();
- //adapter.connect(subject);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- availableSpecificCommands = new ArrayList();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- try {
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- manager = new TelnetManager(url, port, false);
+ }
- } catch (NumberFormatException e1) {
+ if (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- } catch (PerfSONARException e1) {
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.debug("[JuniperIpAdapter] TelnetManager created: " +
url + " "
- + port);
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ }
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ if (temp.equalsIgnoreCase("")) {
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipCommand).getResult();
- logger.debug("[JuniperIpAdapter] Prompt set in TelnetManager:
"
- + prompt);
+ }
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ } else {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- IpCommandInterface ipCommand =
this.getCommand(eventTypeString);
+ } else if (ipCommand.getMinParamCount() == 0 &&
ipCommand.getMaxParamCount() == 0) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (ipCommand.getParameters().size() >= ipCommand
- .getMinParamCount()
- && ipCommand.getParameters().size()
<= ipCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ }
- }
- else {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (ipCommand.getMinParamCount() == 0
- && ipCommand.getMaxParamCount() == 0) {
+ if (temp.equalsIgnoreCase("")) {
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipCommand).getResult();
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ }
- } else {
+ } else {
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- }
+ }
- logger.info("[JuniperIpAdapter] Command executed
succesfully");
+ logger.info("[JuniperIpAdapter] Command executed succesfully");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[JuniperIpAdapter] Constructing response
message");
+ logger.info("[JuniperIpAdapter] Constructing response message");
- Message response = new Message();
+ Message response = new Message();
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- //System.err.println(respMetaData);
- //System.err.println(respData);
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");
- //response.setSonarMetadata(request.getSonarMetadata());
- //response.setSonarData(new Data[] { data });
+ //response.setSonarMetadata(request.getSonarMetadata());
+ //response.setSonarData(new Data[] { data });
- logger.info("[JuniperIpAdapter] takeAction finished");
+ logger.info("[JuniperIpAdapter] takeAction finished");
- return response;
- //return new ServiceEngineResponse();
+ return response;
+ //return new ServiceEngineResponse();
- }
+ }
- // ---------------------- Stand-alond Test Method
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- public static void main(String[] args) {
+ try {
+ JuniperIpAdapter adapter = new JuniperIpAdapter();
- try {
- JuniperIpAdapter adapter = new JuniperIpAdapter();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("juniper1");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("juniper1");
+ adapter.connect("juniper1");
- adapter.connect("juniper1");
+ IpCommandInterface ipCommand;
- IpCommandInterface ipCommand;
+ try {
- try {
+ ipCommand = adapter.getCommand("IP_PIM_RENDEZVOUS");
+ String temp = adapter.executeCommand(ipCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- ipCommand =
adapter.getCommand("IP_PIM_RENDEZVOUS");
- String temp =
adapter.executeCommand(ipCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(adapter.filterResult(temp, ipCommand));
- System.out.println(adapter.filterResult(temp,
ipCommand));
+ } catch (PerfSONARException e) {
- } catch (PerfSONARException e) {
+ //e.printStackTrace();
- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshKeyManager;
@@ -44,631 +45,581 @@
*/
public class JuniperKeyIpAdapter implements IpAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
- // TODO::Should be specified on a higher level -- on the Adapter level
+ // TODO::Should be specified on a higher level -- on the Adapter level
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperKeyIpAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
-
- private String passphrase = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[JUNIPERKEYIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperKeyIpAdapter] Constructor finished");
- // ---------------------- constructors
+ }// JuniperKeyIpAdapter
- public JuniperKeyIpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[JuniperKeyIpAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperKeyIpAdapter] setAvailableSpecificCommand
called");
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(IpCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[JuniperKeyIpAdapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperKeyIpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// JuniperKeyIpAdapter
+ logger.debug("[JuniperKeyIpAdapter] getCommand called");
- // ---------------------- public methods
+ IpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[JuniperKeyIpAdapter]
getAvailableSpecificCommands called");
+ command = (IpCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[JuniperKeyIpAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger
- .debug("[JuniperKeyIpAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperKeyIpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface executeCommand(IpCommandInterface command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(IpCommandInterface command) {
+ logger.debug("[JuniperKeyIpAdapter] executeCommand called");
- logger
- .debug("[JuniperKeyIpAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[JuniperKeyIpAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (IpCommand) it.next();
+ logger.info("[JuniperKeyIpAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[JuniperKeyIpAdapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ try {
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject,
"passphrase");
+ if (username.equals("") || keyUrl.equals("")) {
+ throw new
PerfSONARException("error.mp.sshtelnet.configuration",
+ "Username or KeyURL not set");
+ }
+ } catch (Exception e) {
+ logger.error("[JuniperKeyIpAdapter] Error in
configuration");
+ logger.error(e.getStackTrace().toString());
+ throw e;
+ }
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ if (passphrase == null || passphrase.equals("")) {
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ } else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+
+ }
- logger.error("[JuniperKeyIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[JuniperKeyIpAdapter] Trying to connect");
- }// getCommand
+ //if (passphrase == null || passphrase.equals("")) {
+ //manager.connect(username, keyUrl);
+ //} else {
+ //manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[JuniperKeyIpAdapter] Login");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ } catch (Exception e) {
- logger.debug("[JuniperKeyIpAdapter] executeCommand called");
+ logger.error("[JuniperKeyIpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- if (manager != null) {
+ }
- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ }// connect
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ // ---------------------- field methods
+ public int getPort() {
- }// if
+ return port;
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ }
- }// executeCommand
+ public void setPort(int port) {
- public void connect() {
- }
+ this.port = port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[JuniperKeyIpAdapter] Connect called");
+ public String getPrompt() {
- try {
+ return prompt;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
- if (username.equals("") ||
keyUrl.equals(""))
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Username or
KeyURL not set");
- } catch (Exception e) {
- logger.error("[JuniperKeyIpAdapter]
Error in configuration");
-
logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public void setPrompt(String prompt) {
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ this.prompt = prompt;
- }
+ }
- logger.info("[JuniperKeyIpAdapter] Trying to
connect");
-
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[JuniperKeyIpAdapter] Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger
- .error("[JuniperKeyIpAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[JuniperKeyIpAdapter] Configuring available operations
...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("IP_")) {
- public String getPrompt() {
+ IpCommand command = new IpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[JUNIPERKEYIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ logger.debug("[JuniperKeyIpAdapter] Available operations
configured");
- }
+ }
- public void setUrl(String url) {
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, IpCommandInterface ipCommand) {
- this.url = url;
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- }
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- // ---------------------- Private methods
+ }
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ while (temp.indexOf("---(more") > -1) {
- logger
- .debug("[JuniperKeyIpAdapter] Configuring
available operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- StringTokenizer tokenizer = null;
- String token = null;
+ }
- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- token = tokenizer.nextToken();
- if (token.contains("IP_")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- IpCommand command = new
IpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- logger.debug("[JuniperKeyIpAdapter] Available operations
configured");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, IpCommandInterface
ipCommand) {
+ logger.info("[JuniperKeyIpAdapter] Webservice takeAction call
received");
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- while (temp.indexOf("---(more") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
- }
+ //JuniperKeyIpAdapter adapter = new JuniperKeyIpAdapter();
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ //adapter.connect(subject);
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ availableSpecificCommands = new ArrayList();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ try {
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ try {
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ if (username.equals("") || keyUrl.equals("")) {
+ throw new
PerfSONARException("error.mp.sshtelnet.configuration",
+ "Username or KeyURL not set");
+ }
+ } catch (PerfSONARException e) {
+ logger.error("[JuniperKeyIpAdapter] Error in configuration");
+ logger.error(e.getStackTrace().toString());
+ throw e;
+ }
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- t2 = resultBuffer.toString();
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {
- }
+ logger.error("[JUNIPERKEYIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- // ---------------------- Methods from service engine interface
+ } catch (PerfSONARException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[JUNIPERKEYIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
+ }
- return this.serviceEngineType;
+ logger.debug("[JuniperKeyIpAdapter] TelnetManager created: " + url +
" " + port);
- }
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- logger
- .info("[JuniperKeyIpAdapter] Webservice
takeAction call received");
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ if (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {
- JuniperKeyIpAdapter adapter = new JuniperKeyIpAdapter();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- //adapter.connect(subject);
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- availableSpecificCommands = new ArrayList();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- if (username.equals("") || keyUrl.equals(""))
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Username or KeyURL
not set");
- } catch (PerfSONARException e) {
- logger.error("[JuniperKeyIpAdapter] Error in
configuration");
- logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ if (temp.equalsIgnoreCase("")) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
- }
-
- logger.debug("[JuniperKeyIpAdapter] TelnetManager created: "
+ url
- + " " + port);
+ this.connect(subject);
+ temp = this.executeCommand(ipCommand).getResult();
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ }
- IpCommandInterface ipCommand =
this.getCommand(eventTypeString);
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ } else if (ipCommand.getMinParamCount() == 0) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- }
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (ipCommand.getParameters().size() >= ipCommand
- .getMinParamCount()
- && ipCommand.getParameters().size()
<= ipCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } else if (ipCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else {
+ this.connect(subject);
+ temp = this.executeCommand(ipCommand).getResult();
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ } else {
- logger.info("[JuniperKeyIpAdapter] Command executed
succesfully");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ }
- datum.setDatum(filterResult(temp, ipCommand));
+ logger.info("[JuniperKeyIpAdapter] Command executed succesfully");
- logger.info("[JuniperKeyIpAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Message response = new Message();
+ datum.setDatum(filterResult(temp, ipCommand));
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[JuniperKeyIpAdapter] Constructing response message");
- logger.info("[JuniperKeyIpAdapter] takeAction finished");
+ Message response = new Message();
- return response;
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- }
+ logger.info("[JuniperKeyIpAdapter] takeAction finished");
- // ---------------------- Stand-alond Test Method
+ return response;
- public static void main(String[] args) {
+ }
- try {
- JuniperKeyIpAdapter adapter = new
JuniperKeyIpAdapter();
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ try {
+ JuniperKeyIpAdapter adapter = new JuniperKeyIpAdapter();
- adapter.connect("junipernl");
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("junipernl");
- IpCommandInterface ipCommand;
+ adapter.connect("junipernl");
- try {
+ IpCommandInterface ipCommand;
- ipCommand = adapter.getCommand("IP_TEST");
- String temp =
adapter.executeCommand(ipCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ try {
- System.out.println(adapter.filterResult(temp,
ipCommand));
+ ipCommand = adapter.getCommand("IP_TEST");
+ String temp = adapter.executeCommand(ipCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- } catch (PerfSONARException e) {
+ //System.out.println(adapter.filterResult(temp, ipCommand));
- e.printStackTrace();
+ } catch (PerfSONARException e) {
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ //e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.lookingGlassType.ip.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ip.commands.IpCommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshManager;
@@ -44,616 +45,570 @@
*/
public class JuniperSshIpAdapter implements IpAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
- private String prompt = "";
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private int port = 0;
+ // ---------------------- constructors
+ public JuniperSshIpAdapter() throws PerfSONARException {
- private String username = "";
+ try {
- private String password = "";
-
- private int caching = 0;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- // ---------------------- class-fields
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private List availableSpecificCommands = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private RemoteManager manager = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private LoggerComponent logger = null;
+ } catch (PerfSONARException e) {
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.error("[JUNIPERSSHIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private static List cachedResults = new ArrayList();
+ }
- // ---------------------- constructors
+ logger.debug("[JuniperSshIpAdapter] Constructor started");
- public JuniperSshIpAdapter() throws PerfSONARException {
+ logger.debug("[JuniperSshIpAdapter] Constructor finished");
- try {
+ }// JuniperSshIpAdapter
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ logger.debug("[JuniperSshIpAdapter] getAvailableSpecificCommands
called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ return availableSpecificCommands;
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- } catch (PerfSONARException e) {
+ logger.debug("[JuniperSshIpAdapter] setAvailableSpecificCommand
called");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ this.availableSpecificCommands = availableSpecificCommands;
- }
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(IpCommandInterface command) {
- logger.debug("[JuniperSshIpAdapter] Constructor started");
+ logger.debug("[JuniperSshIpAdapter] addAvailableSpecificCommand
called");
- logger.debug("[JuniperSshIpAdapter] Constructor finished");
+ availableSpecificCommands.add(command);
- }// JuniperSshIpAdapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {
- // ---------------------- public methods
+ logger.debug("[JuniperSshIpAdapter] getCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ IpCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- logger.debug("[JuniperSshIpAdapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {
- return availableSpecificCommands;
+ command = (IpCommand) it.next();
- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[JuniperSshIpAdapter] Command found");
+ return command;
- logger.debug("[JuniperSshIpAdapter]
setAvailableSpecificCommand called");
+ }
- this.availableSpecificCommands = availableSpecificCommands;
+ }// while
- }// setAvailableSpecificCommands
+ logger.error("[JuniperSshIpAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(IpCommandInterface command) {
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface executeCommand(IpCommandInterface command) {
- logger.debug("[JuniperSshIpAdapter]
addAvailableSpecificCommand called");
+ logger.debug("[JuniperSshIpAdapter] executeCommand called");
- availableSpecificCommands.add(command);
+ if (manager != null) {
- }// addAvailableSpecificCommand
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[JuniperSshIpAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperSshIpAdapter] executeCommand finished");
+ return command;
- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (IpCommand) it.next();
+ logger.info("[JuniperSshIpAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[JuniperSshIpAdapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ try {
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ if (username.equals("") || password.equals("")) {
+ throw new
PerfSONARException("error.mp.sshtelnet.configuration",
+ "Username or password not set");
+ }
+ } catch (Exception e) {
+ logger.error("[JuniperSshIpAdapter] Error in
configuration");
+ logger.error(e.getStackTrace().toString());
+ throw e;
+ }
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ //System.out.println(username);
+ //System.out.println(password);
- logger.error("[JuniperSshIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- }// getCommand
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ logger.info("[JuniperSshIpAdapter] Trying to connect");
- logger.debug("[JuniperSshIpAdapter] executeCommand called");
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- if (manager != null) {
+ logger.info("[JuniperSshIpAdapter Login");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ } catch (Exception e) {
- }// if
+ logger.error("[JuniperSshIpAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperSshIpAdapter] executeCommand finished");
- return command;
+ }
- }// executeCommand
+ }// connect
- public void connect() {
- }
+ // ---------------------- field methods
+ public int getPort() {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ return port;
- logger.info("[JuniperSshIpAdapter] Connect called");
+ }
- try {
+ public void setPort(int port) {
- if (manager == null) {
+ this.port = port;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- try {
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- if (username.equals("") ||
password.equals(""))
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Username or
password not set");
- } catch (Exception e) {
- logger.error("[JuniperSshIpAdapter]
Error in configuration");
-
logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- //System.out.println(username);
- //System.out.println(password);
+ public String getPrompt() {
- manager = new SshManager(url, username,
password, false);
+ return prompt;
- }
+ }
- logger.info("[JuniperSshIpAdapter] Trying to
connect");
+ public void setPrompt(String prompt) {
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;
- logger.info("[JuniperSshIpAdapter Login");
+ }
- } catch (Exception e) {
+ public String getUrl() {
- logger.error("[JuniperSshIpAdapter] Error occuring
while connecting");
- //System.err.println("[JuniperSshIpAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ return url;
- }
+ }
- }// connect
+ public void setUrl(String url) {
- // ---------------------- field methods
+ this.url = url;
- public int getPort() {
+ }
- return port;
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- }
+ logger.debug("[JuniperSshIpAdapter] Configuring available operations
...");
- public void setPort(int port) {
+ Iterator commands = null;
+ String token = null;
- this.port = port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public String getPrompt() {
+ token = (String) commands.next();
+ if (token.contains("IP_")) {
- return prompt;
+ IpCommand command = new IpCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHIPADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public String getUrl() {
+ logger.error("[JUNIPERSSHIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- return url;
+ }
- }
+ logger.debug("[JuniperSshIpAdapter] Available operations
configured");
- public void setUrl(String url) {
+ }
- this.url = url;
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, IpCommandInterface ipCommand) {
- }
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- // ---------------------- Private methods
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ }
- logger.debug("[JuniperSshIpAdapter] Configuring available
operations ...");
+ while (temp.indexOf("---(more") > -1) {
- StringTokenizer tokenizer = null;
- String token = null;
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- try {
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- token = tokenizer.nextToken();
- if (token.contains("IP_")) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- IpCommand command = new
IpCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ StringBuffer resultBuffer = new StringBuffer(t2);
- }
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
- } catch (PerfSONARException e) {
+ return t2.replace("" + prompt, "---END---");
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- logger.debug("[JuniperSshIpAdapter] Available operations
configured");
+ return this.serviceEngineType;
- }
+ }
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, IpCommandInterface
ipCommand) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.info("[JuniperSshIpAdapter] Webservice takeAction call
received");
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- }
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- while (temp.indexOf("---(more") > -1) {
+ logger.debug("SUBJECTSTRING: " + subject);
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- }
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ //JuniperSshIpAdapter adapter = new JuniperSshIpAdapter();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ // REPLACED
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ availableSpecificCommands = new ArrayList();
- t2 = resultBuffer.toString();
+ try {
- return t2.replace("" + prompt, "---END---");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- }
+ } catch (NumberFormatException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[JUNIPERSSHIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (PerfSONARException e1) {
- return this.serviceEngineType;
+ logger.error("[JUNIPERSSHIPADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- }
+ }
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- logger.info("[JuniperSshIpAdapter] Webservice takeAction call
received");
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ //
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- JuniperSshIpAdapter adapter = new JuniperSshIpAdapter();
- //adapter.connect(subject);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- // REPLACED
+ }
- availableSpecificCommands = new ArrayList();
+ if (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {
- try {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- } catch (NumberFormatException e1) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- } catch (PerfSONARException e1) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ }
- }
+ }
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ if (temp.equalsIgnoreCase("")) {
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ this.connect(subject);
+ temp = this.executeCommand(ipCommand).getResult();
- //
+ }
- IpCommandInterface ipCommand =
this.getCommand(eventTypeString);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ } else if (ipCommand.getMinParamCount() == 0) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (ipCommand.getParameters().size() >= ipCommand
- .getMinParamCount()
- && ipCommand.getParameters().size()
<= ipCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (ipCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ if (temp.equalsIgnoreCase("")) {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
-
- }
+ this.connect(subject);
+ temp = this.executeCommand(ipCommand).getResult();
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ } else {
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- logger.info("[JuniperSshIpAdapter] Command executed
succesfully");
+ }
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperSshIpAdapter] Command executed succesfully");
- logger.info("[JuniperSshIpAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Message response = new Message();
+ logger.info("[JuniperSshIpAdapter] Constructing response message");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Message response = new Message();
- logger.info("[JuniperSshIpAdapter] takeAction finished");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- return response;
+ logger.info("[JuniperSshIpAdapter] takeAction finished");
- }
+ return response;
- // ---------------------- Stand-alond Test Method
+ }
- public static void main(String[] args) {
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- try {
- JuniperSshIpAdapter adapter = new
JuniperSshIpAdapter();
+ try {
+ JuniperSshIpAdapter adapter = new JuniperSshIpAdapter();
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("juniper2");
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("juniper2");
- adapter.connect("juniper2");
+ adapter.connect("juniper2");
- IpCommandInterface ipCommand;
+ IpCommandInterface ipCommand;
- try {
+ try {
- ipCommand = adapter.getCommand("IP");
- String temp =
adapter.executeCommand(ipCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ ipCommand = adapter.getCommand("IP");
+ String temp = adapter.executeCommand(ipCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e) {
- e.printStackTrace();
+ //e.printStackTrace();
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -19,195 +19,189 @@
*
*/
public class IpCommand implements IpCommandInterface {
-
- // ---------------------- class-fields
-
- private String deviceName = null;
- private String description = null;
- private String command = null;
- private String result = null;
- private List parameters = null;
-
- private int minParamCount = 0;
- private int maxParamCount = 0;
-
- private long timestamp = 0;
-
- // ---------------------- constructors
-
- public IpCommand(String description, String command) {
-
- this.description = description;
- this.command = command;
- parameters = new ArrayList();
-
- }
- // ---------------------- public methods
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getCommand()
- */
- public String getCommand() {
-
- return command;
-
- }
+ // ---------------------- class-fields
+ private String deviceName = null;
+ private String description = null;
+ private String command = null;
+ private String result = null;
+ private List parameters = null;
+ private int minParamCount = 0;
+ private int maxParamCount = 0;
+ private long timestamp = 0;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getDescription()
- */
- public String getDescription() {
-
- return description;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getResult()
- */
- public String getResult() {
-
- return result;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getFilteredResult()
- */
- public String getFilteredResult() {
-
- return getResult();
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getFilteredResult()
- */
- public List getRecordsResult() {
-
- return null;
-
- }
+ // ---------------------- constructors
+ public IpCommand(String description, String command) {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getParameters()
- */
- public List getParameters() {
-
- return parameters;
-
- }
+ this.description = description;
+ this.command = command;
+ parameters = new ArrayList();
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getParameterString()
- */
- public String getParameterString() {
-
- String parameterString = "";
- Iterator it = parameters.iterator();
-
- while (it.hasNext()) {
- parameterString += it.next()+" ";
- }
-
- parameterString.replace("\n", "");
-
- return parameterString;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setCommand(java.lang.String)
- */
- public void setCommand(String command) {
-
- this.command = command;
-
- }
+ // ---------------------- public methods
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getCommand()
+ */
+ public String getCommand() {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setDescription(java.lang.String)
- */
- public void setDescription(String description) {
-
- this.description = description;
-
- }
+ return command;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setResult(java.lang.String)
- */
- public void setResult(String result) {
-
- this.result = result;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setParameters(java.util.List)
- */
- public void setParameters(List parameters) {
-
- this.parameters = parameters;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#addParameter(java.lang.String)
- */
- public void addParameter(String parameter) {
-
- parameters.add(parameter);
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getDescription()
+ */
+ public String getDescription() {
- public int getMinParamCount() {
+ return description;
- return minParamCount;
-
- }
+ }
- public int getMaxParamCount() {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getResult()
+ */
+ public String getResult() {
- return maxParamCount;
-
- }
+ return result;
- public void setMinParamCount(int count) {
+ }
- minParamCount = count;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getFilteredResult()
+ */
+ public String getFilteredResult() {
- public void setMaxParamCount(int count) {
+ return getResult();
- maxParamCount = count;
-
- }
+ }
- public String getDeviceName() {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getFilteredResult()
+ */
+ public List getRecordsResult() {
- return deviceName;
-
- }
+ return null;
- public long getTimestamp() {
+ }
- return timestamp;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getParameters()
+ */
+ public List getParameters() {
- public void setDeviceName(String deviceName) {
+ return parameters;
- this.deviceName = deviceName;
-
- }
+ }
- public void setTimestamp(long timestamp) {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#getParameterString()
+ */
+ public String getParameterString() {
- this.timestamp = timestamp;
-
- }
-
+ String parameterString = "";
+ Iterator it = parameters.iterator();
+
+ while (it.hasNext()) {
+ parameterString += it.next() + " ";
+ }
+
+ parameterString.replace("\n", "");
+
+ return parameterString;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setCommand(java.lang.String)
+ */
+ public void setCommand(String command) {
+
+ this.command = command;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setDescription(java.lang.String)
+ */
+ public void setDescription(String description) {
+
+ this.description = description;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setResult(java.lang.String)
+ */
+ public void setResult(String result) {
+
+ this.result = result;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#setParameters(java.util.List)
+ */
+ public void setParameters(List parameters) {
+
+ this.parameters = parameters;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ipv6.commands.Ipv6CommandInterface#addParameter(java.lang.String)
+ */
+ public void addParameter(String parameter) {
+
+ parameters.add(parameter);
+
+ }
+
+ public int getMinParamCount() {
+
+ return minParamCount;
+
+ }
+
+ public int getMaxParamCount() {
+
+ return maxParamCount;
+
+ }
+
+ public void setMinParamCount(int count) {
+
+ minParamCount = count;
+
+ }
+
+ public void setMaxParamCount(int count) {
+
+ maxParamCount = count;
+
+ }
+
+ public String getDeviceName() {
+
+ return deviceName;
+
+ }
+
+ public long getTimestamp() {
+
+ return timestamp;
+
+ }
+
+ public void setDeviceName(String deviceName) {
+
+ this.deviceName = deviceName;
+
+ }
+
+ public void setTimestamp(long timestamp) {
+
+ this.timestamp = timestamp;
+
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -19,50 +19,49 @@
*/
public interface IpCommandInterface extends CommandInterface {
- public abstract String getDeviceName();
-
- public abstract String getCommand();
+ public abstract String getDeviceName();
- public abstract String getDescription();
+ public abstract String getCommand();
- public abstract String getResult();
+ public abstract String getDescription();
- public abstract String getFilteredResult();
-
- public abstract List getRecordsResult();
+ public abstract String getResult();
- public abstract List getParameters();
-
- public abstract String getParameterString();
-
- public abstract int getMinParamCount();
-
- public abstract int getMaxParamCount();
-
- public abstract long getTimestamp();
+ public abstract String getFilteredResult();
- /**
- * Returns a enumeration of the paramteres, converted into a space
- * seperated string.
- *
- * @return String with space seperated String
- */
- public abstract void setDeviceName(String deviceName);
-
- public abstract void setCommand(String command);
+ public abstract List getRecordsResult();
- public abstract void setDescription(String description);
+ public abstract List getParameters();
- public abstract void setResult(String result);
+ public abstract String getParameterString();
- public abstract void setParameters(List parameters);
+ public abstract int getMinParamCount();
- public abstract void addParameter(String parameter);
-
- public abstract void setMinParamCount(int count);
-
- public abstract void setMaxParamCount(int count);
-
- public abstract void setTimestamp(long timestamp);
+ public abstract int getMaxParamCount();
-}
\ No newline at end of file
+ public abstract long getTimestamp();
+
+ /**
+ * Returns a enumeration of the paramteres, converted into a space
+ * seperated string.
+ *
+ * @return String with space seperated String
+ */
+ public abstract void setDeviceName(String deviceName);
+
+ public abstract void setCommand(String command);
+
+ public abstract void setDescription(String description);
+
+ public abstract void setResult(String result);
+
+ public abstract void setParameters(List parameters);
+
+ public abstract void addParameter(String parameter);
+
+ public abstract void setMinParamCount(int count);
+
+ public abstract void setMaxParamCount(int count);
+
+ public abstract void setTimestamp(long timestamp);
+}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -10,7 +10,6 @@
import org.perfsonar.base.exceptions.PerfSONARException;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
-
/**
* Interface to which device ipv6 statistics providers should adhere
*
@@ -20,53 +19,51 @@
*
*/
public interface Ipv6AdapterInterface {
-
- // ---------------------- interface methods
-
- /**
- * Interface method to query about the device specific command
available
- *
- * @return List All specific StatusCommands for the device
- */
- public abstract List getAvailableSpecificCommands() ;
-
- /**
- * Sets the list with all specific commands available for that device
- *
- * @param availableSpecificCommands
- */
- public abstract void setAvailableSpecificCommands(List
availableSpecificCommands) ;
- /**
- * Adds a specific command to the list of available specific commands
- *
- * @param command
- */
- public abstract void addAvailableSpecificCommand(Ipv6CommandInterface
command) ;
-
- /**
- * Searches for a command supported by the device matching the given
- * description
- *
- * @param description
- * @return Ipv6CommandInterface representing the desirec command
- */
- public abstract Ipv6CommandInterface getCommand(String description)
throws PerfSONARException;
-
- /**
- * Executes the provided command on the remote device
- *
- *
- * @param command The Ipv6Command to be executed command
- * @return Ipv6Command with the results inserted
- */
- public abstract Ipv6CommandInterface
executeCommand(Ipv6CommandInterface command) ;
-
- /**
- * Makes the Adapter connecting to the device
- *
- */
- public abstract void connect() ;
-
- //List of commands that should be available to all status MP to be
included below
+ // ---------------------- interface methods
+ /**
+ * Interface method to query about the device specific command available
+ *
+ * @return List All specific StatusCommands for the device
+ */
+ public abstract List getAvailableSpecificCommands();
+
+ /**
+ * Sets the list with all specific commands available for that device
+ *
+ * @param availableSpecificCommands
+ */
+ public abstract void setAvailableSpecificCommands(List
availableSpecificCommands);
+
+ /**
+ * Adds a specific command to the list of available specific commands
+ *
+ * @param command
+ */
+ public abstract void addAvailableSpecificCommand(Ipv6CommandInterface
command);
+
+ /**
+ * Searches for a command supported by the device matching the given
+ * description
+ *
+ * @param description
+ * @return Ipv6CommandInterface representing the desirec command
+ */
+ public abstract Ipv6CommandInterface getCommand(String description)
throws PerfSONARException;
+
+ /**
+ * Executes the provided command on the remote device
+ *
+ *
+ * @param command The Ipv6Command to be executed command
+ * @return Ipv6Command with the results inserted
+ */
+ public abstract Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command);
+
+ /**
+ * Makes the Adapter connecting to the device
+ *
+ */
+ public abstract void connect();
+ //List of commands that should be available to all status MP to be
included below
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6Command;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.telnet.TelnetManager;
@@ -44,621 +45,569 @@
*/
public class CiscoIpv6Adapter implements Ipv6AdapterInterface, ServiceEngine
{
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
- private String prompt = "";
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private int port = 0;
+ // ---------------------- constructors
+ public CiscoIpv6Adapter() throws PerfSONARException {
- private String username = "";
+ try {
- private String password = "";
-
- private int caching = 0;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- // ---------------------- class-fields
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private List availableSpecificCommands = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private LoggerComponent logger = null;
+ } catch (PerfSONARException e) {
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.error("[CISCOIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private static List cachedResults = new ArrayList();
+ }
- // ---------------------- constructors
+ logger.debug("[CiscoIpv6Adapter] Constructor started");
- public CiscoIpv6Adapter() throws PerfSONARException {
+ logger.debug("[CiscoIpv6Adapter] Constructor finished");
- try {
+ }// CiscoIpv6Adapter
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ logger.debug("[CiscoIpv6Adapter getAvailableSpecificCommands
called");
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ return availableSpecificCommands;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- } catch (PerfSONARException e) {
+ logger.debug("[CiscoIpv6Adapter setAvailableSpecificCommand called");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ this.availableSpecificCommands = availableSpecificCommands;
- }
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {
- logger.debug("[CiscoIpv6Adapter] Constructor started");
+ logger.debug("[CiscoIpv6Adapter addAvailableSpecificCommand called");
- logger.debug("[CiscoIpv6Adapter] Constructor finished");
+ availableSpecificCommands.add(command);
- }// CiscoIpv6Adapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {
- // ---------------------- public methods
+ logger.debug("[CiscoIpv6Adapter getCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- logger.debug("[CiscoIpv6Adapter getAvailableSpecificCommands
called");
+ while (it.hasNext()) {
- return availableSpecificCommands;
+ command = (Ipv6Command) it.next();
- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[CiscoIpv6Adapter Command found");
+ return command;
- logger.debug("[CiscoIpv6Adapter setAvailableSpecificCommand
called");
+ }
- this.availableSpecificCommands = availableSpecificCommands;
+ }// while
- }// setAvailableSpecificCommands
+ logger.error("[CiscoIpv6Adapter Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{
- logger.debug("[CiscoIpv6Adapter addAvailableSpecificCommand
called");
+ logger.debug("[CiscoIpv6Adapter executeCommand called");
- availableSpecificCommands.add(command);
+ if (manager != null) {
- }// addAvailableSpecificCommand
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ manager.disconnect();
- logger.debug("[CiscoIpv6Adapter getCommand called");
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// if
- while (it.hasNext()) {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoIpv6Adapter executeCommand finished");
+ return command;
- command = (Ipv6Command) it.next();
+ }// executeCommand
+ public void connect() {
+ }
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- logger.debug("[CiscoIpv6Adapter Command
found");
- return command;
+ logger.debug("[CiscoIpv6Adapter Connect called");
- }
+ try {
- }// while
+ if (manager == null) {
- logger.error("[CiscoIpv6Adapter Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// getCommand
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ }
- logger.debug("[CiscoIpv6Adapter executeCommand called");
+ logger.debug("[CiscoIpv6Adapter Trying to connect");
- if (manager != null) {
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
+ logger.debug("[CiscoIpv6Adapter Login");
- manager.disconnect();
+ } catch (Exception e) {
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[CiscoIpv6Adapter Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoIpv6Adapter executeCommand finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.debug("[CiscoIpv6Adapter Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public String getPrompt() {
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ return prompt;
- }
+ }
- logger.debug("[CiscoIpv6Adapter Trying to connect");
+ public void setPrompt(String prompt) {
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;
- logger.debug("[CiscoIpv6Adapter Login");
+ }
- } catch (Exception e) {
+ public String getUrl() {
- logger.error("[CiscoIpv6Adapter Error occuring while
connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ return url;
- }
+ }
- }// connect
+ public void setUrl(String url) {
- // ---------------------- field methods
+ this.url = url;
- public int getPort() {
+ }
- return port;
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- }
+ logger.debug("[CiscoIpv6Adapter Configuring available operations
...");
- public void setPort(int port) {
+ Iterator commands = null;
+ String token = null;
- this.port = port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public String getPrompt() {
+ token = (String) commands.next();
+ if (token.contains("IPv6")) {
- return prompt;
+ Ipv6Command command = new Ipv6Command(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+ logger.error("[CISCOIPv6ADAPTER][ConfigureCommands]"
+ e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+ logger.error("[CISCOIPv6ADAPTER][ConfigureCommands]"
+ e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public String getUrl() {
+ logger.error("[CISCOIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- return url;
+ }
- }
+ //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_FORWARDING, "show ipv6 forwarding"));
+ //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_ROUTE, "show ipv6 route"));
- public void setUrl(String url) {
+ logger.debug("[CiscoIpv6Adapter Available operations configured");
- this.url = url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
- // ---------------------- Private methods
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- logger.debug("[CiscoIpv6Adapter Configuring available
operations ...");
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ String tempResult = temp.substring((ipv6Command.getCommand() + " "
+ ipv6Command.getParameterString()).length());
- try {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- token = tokenizer.nextToken();
- if (token.contains("IPv6")) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- Ipv6Command command = new
Ipv6Command(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- } catch (PerfSONARException e) {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ return this.serviceEngineType;
- }
+ }
- //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_FORWARDING, "show ipv6 forwarding"));
- //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_ROUTE, "show ipv6 route"));
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- logger.debug("[CiscoIpv6Adapter Available operations
configured");
+ logger.info("[CiscoIpv6Adapter Webservice takeAction call received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("SUBJECTSTRING: " + subject);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- }
- String tempResult = temp
- .substring((ipv6Command.getCommand() + " "
+ ipv6Command
-
.getParameterString()).length());
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ // REPLACED
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ availableSpecificCommands = new ArrayList();
- t2 = resultBuffer.toString();
+ try {
- return t2.replace("" + prompt, "---END---");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ manager = new TelnetManager(url, port, false, timeout);
- // ---------------------- Methods from service engine interface
+ } catch (NumberFormatException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[CISCOIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return this.serviceEngineType;
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[CISCOIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ }
- logger.info("[CiscoIpv6Adapter Webservice takeAction call
received");
+ logger.debug("[CiscoStatusAdapter] TelnetManager created: " + url +
" " + port);
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ try {
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ } catch (PerfSONARException e) {
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ logger.error("[CISCOIPv6ADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ }
- CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();
- //adapter.connect(subject);
+ logger.debug("[CiscoStatusAdapter] Prompt set in TelnetManager: " +
prompt);
- // REPLACED
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- availableSpecificCommands = new ArrayList();
+ //
- try {
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- manager = new TelnetManager(url, port, false);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- } catch (NumberFormatException e1) {
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {
- }
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- logger.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();
- try {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- } catch (PerfSONARException e) {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- logger.debug("[CiscoStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ }
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ if (temp.equalsIgnoreCase("")) {
- //
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();
- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ }
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ } else if (ipv6Command.getMinParamCount() == 0) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipv6Command.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();
- }
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } else if (ipv6Command.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ } else {
- logger.info("[CiscoIpv6Adapter Command executed succesfully");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ }
- logger.info("[CiscoIpv6Adapter Constructing response
message");
+ logger.info("[CiscoIpv6Adapter Command executed succesfully");
- Message response = new Message();
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[CiscoIpv6Adapter Constructing response message");
- //System.err.println(respMetaData);
- //System.err.println(respData);
+ Message response = new Message();
- //response.setSonarMetadata(request.getSonarMetadata());
- //response.setSonarData(new Data[] { data });
- logger.info("[CiscoIpv6Adapter takeAction finished");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- return response;
- //return new ServiceEngineResponse();
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");
- }
+ //response.setSonarMetadata(request.getSonarMetadata());
+ //response.setSonarData(new Data[] { data });
+ logger.info("[CiscoIpv6Adapter takeAction finished");
- // ---------------------- Stand-alond Test Method
+ return response;
+ //return new ServiceEngineResponse();
- public static void main(String[] args) {
+ }
- try {
- CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco1");
+ try {
+ CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();
- adapter.connect("cisco1");
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco1");
- Ipv6CommandInterface ipv6Command;
+ adapter.connect("cisco1");
- try {
+ Ipv6CommandInterface ipv6Command;
- ipv6Command =
adapter.getCommand("IPv6_ROUTE");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- System.out.println(temp);
+ try {
- } catch (PerfSONARException e) {
+ ipv6Command = adapter.getCommand("IPv6_ROUTE");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- e.printStackTrace();
+ } catch (PerfSONARException e) {
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ //e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 9th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6Command;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshKeyManager;
@@ -43,607 +44,551 @@
*
*/
public class CiscoKeyIpv6Adapter implements Ipv6AdapterInterface,
- ServiceEngine {
+ ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
- // TODO::Should be specified on a higher level -- on the Adapter level
+ // TODO::Should be specified on a higher level -- on the Adapter level
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoKeyIpv6Adapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
-
- private String passphrase = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOKEYIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoKeyIpv6Adapter] Constructor finished");
- // ---------------------- constructors
+ }// CiscoKeyIpv6Adapter
- public CiscoKeyIpv6Adapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[CiscoKeyIpv6Adapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[CiscoKeyIpv6Adapter] setAvailableSpecificCommand
called");
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoKeyIpv6Adapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoKeyIpv6Adapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoKeyIpv6Adapter
+ logger.debug("[CiscoKeyIpv6Adapter] getCommand called");
- // ---------------------- public methods
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[CiscoKeyIpv6Adapter]
getAvailableSpecificCommands called");
+ command = (Ipv6Command) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoKeyIpv6Adapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger
- .debug("[CiscoKeyIpv6Adapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoKeyIpv6Adapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ logger.debug("[CiscoKeyIpv6Adapter] executeCommand called");
- logger
- .debug("[CiscoKeyIpv6Adapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[CiscoKeyIpv6Adapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (Ipv6Command) it.next();
+ logger.info("[CiscoKeyIpv6Adapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[CiscoKeyIpv6Adapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ if (passphrase == null || passphrase.equals("")) {
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ } else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+
+ }
- logger.error("[CiscoKeyIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[CiscoKeyIpv6Adapter] Trying to connect");
- }// getCommand
+ //if (passphrase == null || passphrase.equals("")) {
+ // manager.connect(username, keyUrl);
+ //} else {
+ // manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[CiscoKeyIpv6Adapter] Login");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ } catch (Exception e) {
- logger.debug("[CiscoKeyIpv6Adapter] executeCommand called");
+ logger.error("[CiscoKeyIpv6Adapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- if (manager != null) {
+ }
- // System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ }// connect
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ // ---------------------- field methods
+ public int getPort() {
- }// if
+ return port;
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ }
- }// executeCommand
+ public void setPort(int port) {
- public void connect() {
- }
+ this.port = port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[CiscoKeyIpv6Adapter] Connect called");
+ public String getPrompt() {
- try {
+ return prompt;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public void setPrompt(String prompt) {
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ this.prompt = prompt;
- }
+ }
- logger.info("[CiscoKeyIpv6Adapter] Trying to
connect");
+ public String getUrl() {
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[CiscoKeyIpv6Adapter] Login");
+ return url;
- } catch (Exception e) {
+ }
- logger
- .info("[CiscoKeyIpv6Adapter] Error
occuring while connecting");
- logger.info(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[CiscoKeyIpv6Adapter] Configuring available operations
...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("IPv6_")) {
- }
+ Ipv6Command command = new Ipv6Command(token,
properties.getProperty(subject, token, "command"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+ logger.error("[CISCOKEYIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ logger.debug("[CiscoKeyIpv6Adapter] Available operations
configured");
- return url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
- public void setUrl(String url) {
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- this.url = url;
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- }
+ }
- // ---------------------- Private methods
+ String tempResult = temp.substring((ipv6Command.getCommand() + " "
+ ipv6Command.getParameterString()).length());
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- logger
- .debug("[CiscoKeyIpv6Adapter] Configuring
available operations ...");
+ StringBuffer resultBuffer = new StringBuffer(t2);
- StringTokenizer tokenizer = null;
- String token = null;
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- try {
+ t2 = resultBuffer.toString();
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ return t2.replace("" + prompt, "---END---");
- token = tokenizer.nextToken();
- if (token.contains("IPv6_")) {
+ }
- Ipv6Command command = new
Ipv6Command(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- }
+ }
- } catch (PerfSONARException e) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ logger.info("[CiscoKeyIpv6Adapter] Webservice takeAction call
received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- logger.debug("[CiscoKeyIpv6Adapter] Available operations
configured");
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ //CiscoKeyIpv6Adapter adapter = new CiscoKeyIpv6Adapter();
- String tempResult = temp
- .substring((ipv6Command.getCommand() + " "
+ ipv6Command
-
.getParameterString()).length());
+ availableSpecificCommands = new ArrayList();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ try {
- StringBuffer resultBuffer = new StringBuffer(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {
- return t2.replace("" + prompt, "---END---");
+ logger.error("[CISCOKEYIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- }
+ } catch (PerfSONARException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOKEYIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ }
- return this.serviceEngineType;
+ logger.debug("[CiscoKeyIpv6Adapter] TelnetManager created: " + url +
" " + port);
- }
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException{
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);
- logger
- .info("[CiscoKeyIpv6Adapter] Webservice
takeAction call received");
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ }
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {
- CiscoKeyIpv6Adapter adapter = new CiscoKeyIpv6Adapter();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- //adapter.connect(subject);
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();
- availableSpecificCommands = new ArrayList();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- username = properties.getProperty("service.r.mp." +
subject
- + ".username");
- keyUrl = properties.getProperty("service.r.mp." +
subject
- + ".keyUrl");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ if (temp.equalsIgnoreCase("")) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- }
+ }
- logger.debug("[CiscoKeyIpv6Adapter] TelnetManager created: "
+ url
- + " " + port);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ } else if (ipv6Command.getMinParamCount() == 0) {
- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipv6Command.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- if (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount()
&& valid) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- } else if (ipv6Command.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[CiscoKeyIpv6Adapter] Command executed succesfully");
- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[CiscoKeyIpv6Adapter] Command executed
succesfully");
+ datum.setDatum(filterResult(temp, ipv6Command));
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoKeyIpv6Adapter] Constructing response message");
- datum.setDatum(filterResult(temp, ipv6Command));
+ Message response = new Message();
- logger.info("[CiscoKeyIpv6Adapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.info("[CiscoKeyIpv6Adapter] takeAction finished");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ return response;
- logger.info("[CiscoKeyIpv6Adapter] takeAction finished");
+ }
- return response;
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ CiscoKeyIpv6Adapter adapter = new CiscoKeyIpv6Adapter();
- // ---------------------- Stand-alond Test Method
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("juniperfr");
- public static void main(String[] args) {
+ adapter.connect("juniperfr");
- try {
- CiscoKeyIpv6Adapter adapter = new
CiscoKeyIpv6Adapter();
+ Ipv6CommandInterface ipv6Command;
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniperfr");
+ try {
- adapter.connect("juniperfr");
+ ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- Ipv6CommandInterface ipv6Command;
+ //System.out.println(adapter.filterResult(temp, ipv6Command));
- try {
+ } catch (PerfSONARException e) {
- ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //e.printStackTrace();
- System.out.println(adapter.filterResult(temp,
ipv6Command));
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6Command;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshManager;
@@ -44,595 +45,547 @@
*/
public class CiscoSshIpv6Adapter implements Ipv6AdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoSshIpv6Adapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOSSHIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoSshIpv6Adapter] Constructor started");
- // ---------------------- constructors
+ logger.debug("[CiscoSshIpv6Adapter] Constructor finished");
- public CiscoSshIpv6Adapter() throws PerfSONARException {
+ }// CiscoSshIpv6Adapter
- try {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.debug("[CiscoSshIpv6Adapter] getAvailableSpecificCommands
called");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return availableSpecificCommands;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoSshIpv6Adapter] setAvailableSpecificCommand
called");
- } catch (PerfSONARException e) {
+ this.availableSpecificCommands = availableSpecificCommands;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {
- }
+ logger.debug("[CiscoSshIpv6Adapter] addAvailableSpecificCommand
called");
- logger.debug("[CiscoSshIpv6Adapter] Constructor started");
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoSshIpv6Adapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoSshIpv6Adapter
+ logger.debug("[CiscoSshIpv6Adapter] getCommand called");
- // ---------------------- public methods
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[CiscoSshIpv6Adapter]
getAvailableSpecificCommands called");
+ command = (Ipv6Command) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoSshIpv6Adapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[CiscoSshIpv6Adapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoSshIpv6Adapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ logger.debug("[CiscoSshIpv6Adapter] executeCommand called");
- logger.debug("[CiscoSshIpv6Adapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- }// addAvailableSpecificCommand
+ }// if
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshIpv6Adapter] executeCommand finished");
+ return command;
- logger.debug("[CiscoSshIpv6Adapter] getCommand called");
+ }// executeCommand
+ public void connect() {
+ }
- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- while (it.hasNext()) {
+ logger.info("[CiscoSshIpv6Adapter] Connect called");
- command = (Ipv6Command) it.next();
+ try {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {
- logger.debug("[CiscoSshIpv6Adapter] Command
found");
- return command;
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ //System.out.println(username);
+ //System.out.println(password);
- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- logger.error("[CiscoSshIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }
- }// getCommand
+ logger.info("[CiscoSshIpv6Adapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[CiscoSshIpv6Adapter] executeCommand called");
+ logger.info("[CiscoSshIpv6Adapter Login");
- if (manager != null) {
+ } catch (Exception e) {
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[CiscoSshIpv6Adapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshIpv6Adapter] executeCommand finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[CiscoSshIpv6Adapter] Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public String getPrompt() {
- //System.out.println(username);
- //System.out.println(password);
+ return prompt;
- manager = new SshManager(url, username,
password, false);
+ }
- }
+ public void setPrompt(String prompt) {
- logger.info("[CiscoSshIpv6Adapter] Trying to
connect");
+ this.prompt = prompt;
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }
- logger.info("[CiscoSshIpv6Adapter Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger.error("[CiscoSshIpv6Adapter] Error occuring
while connecting");
- //System.err.println("[CiscoSshIpv6Adapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[CiscoSshIpv6Adapter] Configuring available operations
...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("IPv6")) {
- public String getPrompt() {
+ Ipv6Command command = new Ipv6Command(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[CISCOSSHIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ logger.debug("[CiscoSshIpv6Adapter] Available operations
configured");
- }
+ }
- public void setUrl(String url) {
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
- this.url = url;
+ //logger.debug("result: "+temp);
+
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- }
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- // ---------------------- Private methods
+ }
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ //String tempResult = temp.substring((ipv6Command.getCommand() + "
" + ipv6Command.getParameterString()).length());
- logger.debug("[CiscoSshIpv6Adapter] Configuring available
operations ...");
+ String t1 = temp.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- StringTokenizer tokenizer = null;
- String token = null;
+ StringBuffer resultBuffer = new StringBuffer(t2);
- try {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ t2 = resultBuffer.toString();
- token = tokenizer.nextToken();
- if (token.contains("IPv6")) {
+ return t2.replace("" + prompt, "---END---");
- Ipv6Command command = new
Ipv6Command(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- } catch (PerfSONARException e) {
+ }
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- }
+ logger.info("[CiscoSshIpv6Adapter] Webservice takeAction call
received");
- logger.debug("[CiscoSshIpv6Adapter] Available operations
configured");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- }
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
+ logger.debug("SUBJECTSTRING: " + subject);
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String tempResult = temp
- .substring((ipv6Command.getCommand() + " "
+ ipv6Command
-
.getParameterString()).length());
+ //CiscoSshIpv6Adapter adapter = new CiscoSshIpv6Adapter();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ // REPLACED
- StringBuffer resultBuffer = new StringBuffer(t2);
+ availableSpecificCommands = new ArrayList();
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ try {
- t2 = resultBuffer.toString();
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {
- }
+ logger.error("[CISCOSSHIPv6ADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- // ---------------------- Methods from service engine interface
+ } catch (PerfSONARException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[CISCOSSHIPv6ADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- return this.serviceEngineType;
+ }
- }
+ logger.debug("[CiscoSshIpv6Adapter] SshManager created: " + url + "
" + port);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- logger.info("[CiscoSshIpv6Adapter] Webservice takeAction call
received");
+
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- CiscoSshIpv6Adapter adapter = new CiscoSshIpv6Adapter();
- //adapter.connect(subject);
+ }
- // REPLACED
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {
- availableSpecificCommands = new ArrayList();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- try {
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- } catch (NumberFormatException e1) {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ }
- }
+ if (temp.equalsIgnoreCase("")) {
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ }
- //
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ } else if (ipv6Command.getMinParamCount() == 0) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipv6Command.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (ipv6Command.getMinParamCount() == 0) {
+ if (temp.equalsIgnoreCase("")) {
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ }
- } else {
+ } else {
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- }
+ }
- logger.info("[CiscoSshIpv6Adapter] Command executed
succesfully");
+ logger.info("[CiscoSshIpv6Adapter] Command executed succesfully");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[CiscoSshIpv6Adapter] Constructing response
message");
+ logger.info("[CiscoSshIpv6Adapter] Constructing response message");
- Message response = new Message();
+ Message response = new Message();
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- logger.info("[CiscoSshIpv6Adapter] takeAction finished");
+ logger.info("[CiscoSshIpv6Adapter] takeAction finished");
- return response;
+ return response;
- }
+ }
- // ---------------------- Stand-alond Test Method
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- public static void main(String[] args) {
+ try {
+ CiscoSshIpv6Adapter adapter = new CiscoSshIpv6Adapter();
- try {
- CiscoSshIpv6Adapter adapter = new
CiscoSshIpv6Adapter();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco2");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco2");
+ adapter.connect("cisco2");
- adapter.connect("cisco2");
+ Ipv6CommandInterface ipv6Command;
- Ipv6CommandInterface ipv6Command;
+ try {
- try {
+ ipv6Command = adapter.getCommand("IPv6_ROUTE");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- ipv6Command =
adapter.getCommand("IPv6_ROUTE");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ } catch (PerfSONARException e) {
- } catch (PerfSONARException e) {
+ //e.printStackTrace();
- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6Command;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.telnet.TelnetManager;
@@ -44,627 +45,574 @@
*/
public class JuniperIpv6Adapter implements Ipv6AdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
- private String prompt = "";
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private int port = 0;
+ // ---------------------- constructors
+ public JuniperIpv6Adapter() throws PerfSONARException {
- private String username = "";
+ try {
- private String password = "";
-
- private int caching = 0;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- // ---------------------- class-fields
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private LoggerComponent logger = null;
+ } catch (PerfSONARException e) {
- private PropertiesConfigurationComponent properties = null;
+ logger.error("[JUNIPERIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
-
- // ---------------------- constructors
+ logger.debug("[JuniperIpv6Adapter] Constructor finished");
- public JuniperIpv6Adapter() throws PerfSONARException {
+ }// JuniperIpv6Adapter
- try {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.debug("[JuniperIpv6Adapter getAvailableSpecificCommands
called");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return availableSpecificCommands;
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperIpv6Adapter setAvailableSpecificCommand
called");
- } catch (PerfSONARException e) {
+ this.availableSpecificCommands = availableSpecificCommands;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {
- }
+ logger.debug("[JuniperIpv6Adapter addAvailableSpecificCommand
called");
- logger.debug("[JuniperIpv6Adapter] Constructor finished");
+ availableSpecificCommands.add(command);
- }// JuniperIpv6Adapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {
- // ---------------------- public methods
+ logger.debug("[JuniperIpv6Adapter getCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- logger.debug("[JuniperIpv6Adapter
getAvailableSpecificCommands called");
+ while (it.hasNext()) {
- return availableSpecificCommands;
+ command = (Ipv6Command) it.next();
- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[JuniperIpv6Adapter Command found");
+ return command;
- logger.debug("[JuniperIpv6Adapter setAvailableSpecificCommand
called");
+ }
- this.availableSpecificCommands = availableSpecificCommands;
+ }// while
- }// setAvailableSpecificCommands
+ logger.error("[JuniperIpv6Adapter Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{
- logger.debug("[JuniperIpv6Adapter addAvailableSpecificCommand
called");
+ logger.debug("[JuniperIpv6Adapter executeCommand called");
- availableSpecificCommands.add(command);
+ if (manager != null) {
- }// addAvailableSpecificCommand
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ manager.disconnect();
- logger.debug("[JuniperIpv6Adapter getCommand called");
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// if
- while (it.hasNext()) {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperIpv6Adapter executeCommand finished");
+ return command;
- command = (Ipv6Command) it.next();
+ }// executeCommand
+ public void connect() {
+ }
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- logger.debug("[JuniperIpv6Adapter Command
found");
- return command;
+ logger.debug("[JuniperIpv6Adapter Connect called");
- }
+ try {
- }// while
+ if (manager == null) {
- logger.error("[JuniperIpv6Adapter Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// getCommand
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ }
- logger.debug("[JuniperIpv6Adapter executeCommand called");
+ logger.debug("[JuniperIpv6Adapter Trying to connect");
- if (manager != null) {
+ manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
+ logger.debug("[JuniperIpv6Adapter Login");
- manager.disconnect();
+ } catch (Exception e) {
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[JuniperIpv6Adapter Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperIpv6Adapter executeCommand finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.debug("[JuniperIpv6Adapter Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public String getPrompt() {
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ return prompt;
- }
+ }
- logger.debug("[JuniperIpv6Adapter Trying to connect");
+ public void setPrompt(String prompt) {
- manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;
- logger.debug("[JuniperIpv6Adapter Login");
+ }
- } catch (Exception e) {
+ public String getUrl() {
- logger.error("[JuniperIpv6Adapter Error occuring
while connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ return url;
- }
+ }
- }// connect
+ public void setUrl(String url) {
- // ---------------------- field methods
+ this.url = url;
- public int getPort() {
+ }
- return port;
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- }
+ logger.debug("[JuniperIpv6Adapter Configuring available operations
...");
- public void setPort(int port) {
+ Iterator commands = null;
+ String token = null;
- this.port = port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public String getPrompt() {
+ token = (String) commands.next();
+ if (token.contains("IPv6")) {
- return prompt;
+ Ipv6Command command = new Ipv6Command(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public String getUrl() {
+ logger.error("[JUNIPERIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- return url;
+ }
- }
+ // this.addAvailableSpecificCommand(new
+ // Ipv6Command(ActionType.MP_IPv6_FORWARDING, "show ipv6
forwarding"));
+ // this.addAvailableSpecificCommand(new
+ // Ipv6Command(ActionType.MP_IPv6_ROUTE, "show ipv6 route"));
- public void setUrl(String url) {
+ logger.debug("[JuniperIpv6Adapter Available operations configured");
- this.url = url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
- // ---------------------- Private methods
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- logger
- .debug("[JuniperIpv6Adapter Configuring
available operations ...");
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ while (temp.indexOf("---(more") > 0) {
- try {
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ }
- token = tokenizer.nextToken();
- if (token.contains("IPv6")) {
+ String tempResult = temp.substring((ipv6Command.getCommand() + " "
+ ipv6Command.getParameterString()).length());
- Ipv6Command command = new
Ipv6Command(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- }
+ StringBuffer resultBuffer = new StringBuffer(t2);
- }
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- } catch (PerfSONARException e) {
+ t2 = resultBuffer.toString();
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- // this.addAvailableSpecificCommand(new
- // Ipv6Command(ActionType.MP_IPv6_FORWARDING, "show ipv6
forwarding"));
- // this.addAvailableSpecificCommand(new
- // Ipv6Command(ActionType.MP_IPv6_ROUTE, "show ipv6 route"));
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- logger.debug("[JuniperIpv6Adapter Available operations
configured");
+ return this.serviceEngineType;
- }
+ }
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.info("[JuniperIpv6Adapter Webservice takeAction call
received");
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- }
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- while (temp.indexOf("---(more") > 0) {
+ logger.debug("SUBJECTSTRING: " + subject);
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- }
- String tempResult = temp
- .substring((ipv6Command.getCommand() + " "
+ ipv6Command
-
.getParameterString()).length());
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ availableSpecificCommands = new ArrayList();
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ try {
- t2 = resultBuffer.toString();
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- return t2.replace("" + prompt, "---END---");
+ manager = new TelnetManager(url, port, false, timeout);
- }
+ } catch (NumberFormatException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[JUNIPERIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (PerfSONARException e1) {
- return this.serviceEngineType;
+ logger.error("[JUNIPERIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- }
+ }
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.debug("[JuniperIpv6Adapter] TelnetManager created: " + url +
" " + port);
- logger.info("[JuniperIpv6Adapter Webservice takeAction call
received");
+ try {
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ } catch (PerfSONARException e) {
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.error("[JUNIPERIPv6ADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ }
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ logger.debug("[JuniperIpv6Adapter] Prompt set in TelnetManager: " +
prompt);
- JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();
- //adapter.connect(subject);
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- availableSpecificCommands = new ArrayList();
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);
- try {
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- manager = new TelnetManager(url, port, false);
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- } catch (NumberFormatException e1) {
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- }
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();
- logger.debug("[JuniperIpv6Adapter] TelnetManager created: " +
url + " "
- + port);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- } catch (PerfSONARException e) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ }
- }
+ }
- logger.debug("[JuniperIpv6Adapter] Prompt set in
TelnetManager: "
- + prompt);
+ if (temp.equalsIgnoreCase("")) {
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();
- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ }
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ } else if (ipv6Command.getMinParamCount() == 0) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipv6Command.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();
- }
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } else if (ipv6Command.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ } else {
- logger.info("[JuniperIpv6Adapter Command executed
succesfully");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ }
- logger.info("[JuniperIpv6Adapter Constructing response
message");
+ logger.info("[JuniperIpv6Adapter Command executed succesfully");
- Message response = new Message();
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[JuniperIpv6Adapter Constructing response message");
- // System.err.println(respMetaData);
- // System.err.println(respData);
+ Message response = new Message();
- // response.setSonarMetadata(request.getSonarMetadata());
- // response.setSonarData(new Data[] { data });
- logger.info("[JuniperIpv6Adapter takeAction finished");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- return response;
- // return new ServiceEngineResponse();
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");
- }
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });
+ logger.info("[JuniperIpv6Adapter takeAction finished");
- // ---------------------- Stand-alond Test Method
+ return response;
+ // return new ServiceEngineResponse();
- public static void main(String[] args) {
+ }
- try {
- JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniper1");
+ try {
+ JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();
- adapter.connect("juniper1");
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("juniper1");
- Ipv6CommandInterface ipv6Command;
+ adapter.connect("juniper1");
- try {
+ Ipv6CommandInterface ipv6Command;
- ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ try {
- System.out.println(adapter.filterResult(temp,
ipv6Command));
+ ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- } catch (PerfSONARException e) {
+ //System.out.println(adapter.filterResult(temp, ipv6Command));
- e.printStackTrace();
+ } catch (PerfSONARException e) {
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ //e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6Command;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshKeyManager;
@@ -43,619 +44,564 @@
*
*/
public class JuniperKeyIpv6Adapter implements Ipv6AdapterInterface,
- ServiceEngine {
+ ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
- // TODO::Should be specified on a higher level -- on the Adapter level
+ // TODO::Should be specified on a higher level -- on the Adapter level
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperKeyIpv6Adapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
-
- private String passphrase = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[JUNIPERKEYIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperKeyIpv6Adapter] Constructor finished");
- // ---------------------- constructors
+ }// JuniperKeyIpv6Adapter
- public JuniperKeyIpv6Adapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[JuniperKeyIpv6Adapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperKeyIpv6Adapter] setAvailableSpecificCommand
called");
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[JuniperKeyIpv6Adapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperKeyIpv6Adapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// JuniperKeyIpv6Adapter
+ logger.debug("[JuniperKeyIpv6Adapter] getCommand called");
- // ---------------------- public methods
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[JuniperKeyIpv6Adapter]
getAvailableSpecificCommands called");
+ command = (Ipv6Command) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[JuniperKeyIpv6Adapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger
- .debug("[JuniperKeyIpv6Adapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperKeyIpv6Adapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ logger.debug("[JuniperKeyIpv6Adapter] executeCommand called");
- logger
- .debug("[JuniperKeyIpv6Adapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[JuniperKeyIpv6Adapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (Ipv6Command) it.next();
+ logger.info("[JuniperKeyIpv6Adapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[JuniperKeyIpv6Adapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ if (passphrase == null || passphrase.equals(""))
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+ }
- logger.error("[JuniperKeyIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[JuniperKeyIpv6Adapter] Trying to connect");
- }// getCommand
+ //if (passphrase == null || passphrase.equals("")) {
+ // manager.connect(username, keyUrl);
+ //} else {
+ // manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[JuniperKeyIpv6Adapter] Login");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ } catch (Exception e) {
- logger.debug("[JuniperKeyIpv6Adapter] executeCommand called");
+ logger.error("[JuniperKeyIpv6Adapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- if (manager != null) {
+ }
- // System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ }// connect
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ // ---------------------- field methods
+ public int getPort() {
- }// if
+ return port;
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ }
- }// executeCommand
+ public void setPort(int port) {
- public void connect() {
- }
+ this.port = port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[JuniperKeyIpv6Adapter] Connect called");
+ public String getPrompt() {
- try {
+ return prompt;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + "passphrase");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public void setPrompt(String prompt) {
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ this.prompt = prompt;
- }
+ }
- logger.info("[JuniperKeyIpv6Adapter] Trying to
connect");
+ public String getUrl() {
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[JuniperKeyIpv6Adapter] Login");
+ return url;
- } catch (Exception e) {
+ }
- logger
- .info("[JuniperKeyIpv6Adapter] Error
occuring while connecting");
- logger.info(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[JuniperKeyIpv6Adapter] Configuring available
operations ...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("IPv6_")) {
- }
+ Ipv6Command command = new Ipv6Command(token,
properties.getProperty(subject, token, "command"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+ logger.error("[JUNIPERKEYIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ logger.debug("[JuniperKeyIpv6Adapter] Available operations
configured");
- return url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
- public void setUrl(String url) {
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- this.url = url;
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- }
+ }
- // ---------------------- Private methods
+ while (temp.indexOf("---(more") > -1) {
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- logger
- .debug("[JuniperKeyIpv6Adapter] Configuring
available operations ...");
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- try {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- token = tokenizer.nextToken();
- if (token.contains("IPv6_")) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- Ipv6Command command = new
Ipv6Command(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- } catch (PerfSONARException e) {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ return this.serviceEngineType;
- }
+ }
- logger.debug("[JuniperKeyIpv6Adapter] Available operations
configured");
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- }
+ logger.info("[JuniperKeyIpv6Adapter] Webservice takeAction call
received");
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("SUBJECTSTRING: " + subject);
- }
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- while (temp.indexOf("---(more") > -1) {
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ //JuniperKeyIpv6Adapter adapter = new JuniperKeyIpv6Adapter();
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ availableSpecificCommands = new ArrayList();
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ try {
- StringBuffer resultBuffer = new StringBuffer(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {
- return t2.replace("" + prompt, "---END---");
+ logger.error("[JUNIPERKEYIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- }
+ } catch (PerfSONARException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[JUNIPERKEYIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ }
- return this.serviceEngineType;
+ logger.debug("[JuniperKeyIpv6Adapter] TelnetManager created: " + url
+ " " + port);
- }
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);
- logger
- .info("[JuniperKeyIpv6Adapter] Webservice
takeAction call received");
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ }
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {
- JuniperKeyIpv6Adapter adapter = new JuniperKeyIpv6Adapter();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- //adapter.connect(subject);
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();
- availableSpecificCommands = new ArrayList();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- username = properties.getProperty("service.r.mp." +
subject
- + ".username");
- keyUrl = properties.getProperty("service.r.mp." +
subject
- + ".keyUrl");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ if (temp.equalsIgnoreCase("")) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- }
+ }
- logger.debug("[JuniperKeyIpv6Adapter] TelnetManager created:
" + url
- + " " + port);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ } else if (ipv6Command.getMinParamCount() == 0) {
- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipv6Command.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- if (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount()
&& valid) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- } else if (ipv6Command.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[JuniperKeyIpv6Adapter] Command executed succesfully");
- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[JuniperKeyIpv6Adapter] Command executed
succesfully");
+ datum.setDatum(filterResult(temp, ipv6Command));
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperKeyIpv6Adapter] Constructing response message");
- datum.setDatum(filterResult(temp, ipv6Command));
+ Message response = new Message();
- logger.info("[JuniperKeyIpv6Adapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.info("[JuniperKeyIpv6Adapter] takeAction finished");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ return response;
- logger.info("[JuniperKeyIpv6Adapter] takeAction finished");
+ }
- return response;
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ JuniperKeyIpv6Adapter adapter = new JuniperKeyIpv6Adapter();
- // ---------------------- Stand-alond Test Method
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("juniperfr");
- public static void main(String[] args) {
+ adapter.connect("juniperfr");
- try {
- JuniperKeyIpv6Adapter adapter = new
JuniperKeyIpv6Adapter();
+ Ipv6CommandInterface ipv6Command;
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniperfr");
+ try {
- adapter.connect("juniperfr");
+ ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- Ipv6CommandInterface ipv6Command;
+ //System.out.println(adapter.filterResult(temp, ipv6Command));
- try {
+ } catch (PerfSONARException e) {
- ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //e.printStackTrace();
- System.out.println(adapter.filterResult(temp,
ipv6Command));
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,15 +20,17 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6Command;
import
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.commands.Ipv6CommandInterface;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import org.perfsonar.service.measurementPoint.remote.ssh.SshManager;
@@ -44,607 +45,559 @@
*/
public class JuniperSshIpv6Adapter implements Ipv6AdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperSshIpv6Adapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private int caching = 0;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- // ---------------------- class-fields
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ } catch (PerfSONARException e) {
- private RemoteManager manager = null;
+ logger.error("[JUNIPERSSHIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private LoggerComponent logger = null;
+ }
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[JuniperSshIpv6Adapter] Constructor started");
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperSshIpv6Adapter] Constructor finished");
- // ---------------------- constructors
+ }// JuniperSshIpv6Adapter
- public JuniperSshIpv6Adapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[JuniperSshIpv6Adapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperSshIpv6Adapter] setAvailableSpecificCommand
called");
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[JuniperSshIpv6Adapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperSshIpv6Adapter] Constructor started");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {
- logger.debug("[JuniperSshIpv6Adapter] Constructor finished");
+ logger.debug("[JuniperSshIpv6Adapter] getCommand called");
- }// JuniperSshIpv6Adapter
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- // ---------------------- public methods
+ while (it.hasNext()) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ command = (Ipv6Command) it.next();
- logger.debug("[JuniperSshIpv6Adapter]
getAvailableSpecificCommands called");
+ if (command.getDescription().equalsIgnoreCase(description)) {
- return availableSpecificCommands;
+ logger.debug("[JuniperSshIpv6Adapter] Command found");
+ return command;
- }// getAvailableSpecificCommands
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while
- logger.debug("[JuniperSshIpv6Adapter]
setAvailableSpecificCommand called");
+ logger.error("[JuniperSshIpv6Adapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- this.availableSpecificCommands = availableSpecificCommands;
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{
- }// setAvailableSpecificCommands
+ logger.debug("[JuniperSshIpv6Adapter] executeCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ if (manager != null) {
- logger.debug("[JuniperSshIpv6Adapter]
addAvailableSpecificCommand called");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- availableSpecificCommands.add(command);
+ }// if
- }// addAvailableSpecificCommand
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperSshIpv6Adapter] executeCommand finished");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// executeCommand
+ public void connect() {
+ }
- logger.debug("[JuniperSshIpv6Adapter] getCommand called");
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("[JuniperSshIpv6Adapter] Connect called");
- while (it.hasNext()) {
+ try {
- command = (Ipv6Command) it.next();
+ if (manager == null) {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- logger.debug("[JuniperSshIpv6Adapter] Command
found");
- return command;
+ //System.out.println(username);
+ //System.out.println(password);
- }
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- }// while
+ }
- logger.error("[JuniperSshIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[JuniperSshIpv6Adapter] Trying to connect");
- }// getCommand
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ logger.info("[JuniperSshIpv6Adapter Login");
- logger.debug("[JuniperSshIpv6Adapter] executeCommand called");
+ } catch (Exception e) {
- if (manager != null) {
+ logger.error("[JuniperSshIpv6Adapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }
- }// if
+ }// connect
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperSshIpv6Adapter] executeCommand
finished");
- return command;
+ // ---------------------- field methods
+ public int getPort() {
- }// executeCommand
+ return port;
- public void connect() {
- }
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public void setPort(int port) {
- logger.info("[JuniperSshIpv6Adapter] Connect called");
+ this.port = port;
- try {
+ }
- if (manager == null) {
+ public String getPrompt() {
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ return prompt;
- //System.out.println(username);
- //System.out.println(password);
+ }
- manager = new SshManager(url, username,
password, false);
+ public void setPrompt(String prompt) {
- }
+ this.prompt = prompt;
- logger.info("[JuniperSshIpv6Adapter] Trying to
connect");
+ }
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ public String getUrl() {
- logger.info("[JuniperSshIpv6Adapter Login");
+ return url;
- } catch (Exception e) {
+ }
- logger.error("[JuniperSshIpv6Adapter] Error occuring
while connecting");
- //System.err.println("[JuniperSshIpv6Adapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[JuniperSshIpv6Adapter] Configuring available
operations ...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("IPv6_")) {
- }
+ Ipv6Command command = new Ipv6Command(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHIPv6ADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+ logger.error("[JUNIPERSSHIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ logger.debug("[JuniperSshIpv6Adapter] Available operations
configured");
- return url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
- public void setUrl(String url) {
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- this.url = url;
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- }
+ }
- // ---------------------- Private methods
+ while (temp.indexOf("---(more") > -1) {
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- logger.debug("[JuniperSshIpv6Adapter] Configuring available
operations ...");
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- try {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- token = tokenizer.nextToken();
- if (token.contains("IPv6_")) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- Ipv6Command command = new
Ipv6Command(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- } catch (PerfSONARException e) {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ return this.serviceEngineType;
- }
+ }
- logger.debug("[JuniperSshIpv6Adapter] Available operations
configured");
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- }
+ logger.info("[JuniperSshIpv6Adapter] Webservice takeAction call
received");
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, Ipv6CommandInterface
ipv6Command) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("SUBJECTSTRING: " + subject);
- }
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- while (temp.indexOf("---(more") > -1) {
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ //JuniperSshIpv6Adapter adapter = new JuniperSshIpv6Adapter();
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ // REPLACED
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ availableSpecificCommands = new ArrayList();
- StringBuffer resultBuffer = new StringBuffer(t2);
+ try {
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {
- return t2.replace("" + prompt, "---END---");
+ logger.error("[JUNIPERSSHIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- }
+ } catch (PerfSONARException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[JUNIPERSSHIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ }
- return this.serviceEngineType;
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- }
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ //
- logger.info("[JuniperSshIpv6Adapter] Webservice takeAction
call received");
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ }
- JuniperSshIpv6Adapter adapter = new JuniperSshIpv6Adapter();
- //adapter.connect(subject);
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {
- // REPLACED
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- availableSpecificCommands = new ArrayList();
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();
- try {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- } catch (NumberFormatException e1) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ if (temp.equalsIgnoreCase("")) {
- }
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ }
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- //
+ } else if (ipv6Command.getMinParamCount() == 0) {
- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- ipv6Command.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- if (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (ipv6Command.getMinParamCount() == 0) {
+ this.connect(subject);
+ temp = this.executeCommand(ipv6Command).getResult();
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ } else {
- } else {
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ logger.info("[JuniperSshIpv6Adapter] Command executed succesfully");
- logger.info("[JuniperSshIpv6Adapter] Command executed
succesfully");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperSshIpv6Adapter] Constructing response message");
- logger.info("[JuniperSshIpv6Adapter] Constructing response
message");
+ Message response = new Message();
- Message response = new Message();
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[JuniperSshIpv6Adapter] takeAction finished");
- logger.info("[JuniperSshIpv6Adapter] takeAction finished");
+ return response;
- return response;
+ }
- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // ---------------------- Stand-alond Test Method
+ try {
+ JuniperSshIpv6Adapter adapter = new JuniperSshIpv6Adapter();
- public static void main(String[] args) {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("juniper2");
- try {
- JuniperSshIpv6Adapter adapter = new
JuniperSshIpv6Adapter();
+ adapter.connect("juniper2");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("juniper2");
+ Ipv6CommandInterface ipv6Command;
- adapter.connect("juniper2");
+ try {
- Ipv6CommandInterface ipv6Command;
+ ipv6Command = adapter.getCommand("IPv6");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- try {
+ } catch (PerfSONARException e) {
- ipv6Command = adapter.getCommand("IPv6");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ //e.printStackTrace();
- } catch (PerfSONARException e) {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -19,195 +19,189 @@
*
*/
public class Ipv6Command implements Ipv6CommandInterface {
-
- // ---------------------- class-fields
-
- private String deviceName = null;
- private String description = null;
- private String command = null;
- private String result = null;
- private List parameters = null;
-
- private int minParamCount = 0;
- private int maxParamCount = 0;
-
- private long timestamp = 0;
-
- // ---------------------- constructors
-
- public Ipv6Command(String description, String command) {
-
- this.description = description;
- this.command = command;
- parameters = new ArrayList();
-
- }
- // ---------------------- public methods
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getCommand()
- */
- public String getCommand() {
-
- return command;
-
- }
+ // ---------------------- class-fields
+ private String deviceName = null;
+ private String description = null;
+ private String command = null;
+ private String result = null;
+ private List parameters = null;
+ private int minParamCount = 0;
+ private int maxParamCount = 0;
+ private long timestamp = 0;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getDescription()
- */
- public String getDescription() {
-
- return description;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getResult()
- */
- public String getResult() {
-
- return result;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getFilteredResult()
- */
- public String getFilteredResult() {
-
- return getResult();
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getFilteredResult()
- */
- public List getRecordsResult() {
-
- return null;
-
- }
+ // ---------------------- constructors
+ public Ipv6Command(String description, String command) {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getParameters()
- */
- public List getParameters() {
-
- return parameters;
-
- }
+ this.description = description;
+ this.command = command;
+ parameters = new ArrayList();
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getParameterString()
- */
- public String getParameterString() {
-
- String parameterString = "";
- Iterator it = parameters.iterator();
-
- while (it.hasNext()) {
- parameterString += it.next();
- }
-
- parameterString.replace("\n", "");
-
- return parameterString;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setCommand(java.lang.String)
- */
- public void setCommand(String command) {
-
- this.command = command;
-
- }
+ // ---------------------- public methods
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getCommand()
+ */
+ public String getCommand() {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setDescription(java.lang.String)
- */
- public void setDescription(String description) {
-
- this.description = description;
-
- }
+ return command;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setResult(java.lang.String)
- */
- public void setResult(String result) {
-
- this.result = result;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setParameters(java.util.List)
- */
- public void setParameters(List parameters) {
-
- this.parameters = parameters;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#addParameter(java.lang.String)
- */
- public void addParameter(String parameter) {
-
- parameters.add(parameter);
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getDescription()
+ */
+ public String getDescription() {
- public int getMinParamCount() {
+ return description;
- return minParamCount;
-
- }
+ }
- public int getMaxParamCount() {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getResult()
+ */
+ public String getResult() {
- return maxParamCount;
-
- }
+ return result;
- public void setMinParamCount(int count) {
+ }
- minParamCount = count;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getFilteredResult()
+ */
+ public String getFilteredResult() {
- public void setMaxParamCount(int count) {
+ return getResult();
- maxParamCount = count;
-
- }
+ }
- public long getTimestamp() {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getFilteredResult()
+ */
+ public List getRecordsResult() {
- return timestamp;
-
- }
+ return null;
- public void setTimestamp(long timestamp) {
+ }
- this.timestamp = timestamp;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getParameters()
+ */
+ public List getParameters() {
- public String getDeviceName() {
+ return parameters;
- return deviceName;
-
- }
+ }
- public void setDeviceName(String deviceName) {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#getParameterString()
+ */
+ public String getParameterString() {
- this.deviceName = deviceName;
-
- }
-
+ String parameterString = "";
+ Iterator it = parameters.iterator();
+
+ while (it.hasNext()) {
+ parameterString += it.next();
+ }
+
+ parameterString.replace("\n", "");
+
+ return parameterString;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setCommand(java.lang.String)
+ */
+ public void setCommand(String command) {
+
+ this.command = command;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setDescription(java.lang.String)
+ */
+ public void setDescription(String description) {
+
+ this.description = description;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setResult(java.lang.String)
+ */
+ public void setResult(String result) {
+
+ this.result = result;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#setParameters(java.util.List)
+ */
+ public void setParameters(List parameters) {
+
+ this.parameters = parameters;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.lookingGlass.ip.commands.IpCommandInterface#addParameter(java.lang.String)
+ */
+ public void addParameter(String parameter) {
+
+ parameters.add(parameter);
+
+ }
+
+ public int getMinParamCount() {
+
+ return minParamCount;
+
+ }
+
+ public int getMaxParamCount() {
+
+ return maxParamCount;
+
+ }
+
+ public void setMinParamCount(int count) {
+
+ minParamCount = count;
+
+ }
+
+ public void setMaxParamCount(int count) {
+
+ maxParamCount = count;
+
+ }
+
+ public long getTimestamp() {
+
+ return timestamp;
+
+ }
+
+ public void setTimestamp(long timestamp) {
+
+ this.timestamp = timestamp;
+
+ }
+
+ public String getDeviceName() {
+
+ return deviceName;
+
+ }
+
+ public void setDeviceName(String deviceName) {
+
+ this.deviceName = deviceName;
+
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -19,50 +19,49 @@
*/
public interface Ipv6CommandInterface extends CommandInterface {
- public abstract String getDeviceName();
-
- public abstract String getCommand();
+ public abstract String getDeviceName();
- public abstract String getDescription();
+ public abstract String getCommand();
- public abstract String getResult();
+ public abstract String getDescription();
- public abstract String getFilteredResult();
-
- public abstract List getRecordsResult();
+ public abstract String getResult();
- public abstract List getParameters();
-
- public abstract String getParameterString();
-
- public abstract int getMinParamCount();
-
- public abstract int getMaxParamCount();
-
- public abstract long getTimestamp();
+ public abstract String getFilteredResult();
- /**
- * Returns a enumeration of the paramteres, converted into a space
- * seperated string.
- *
- * @return String with space seperated String
- */
- public abstract void setDeviceName(String deviceName);
-
- public abstract void setCommand(String command);
+ public abstract List getRecordsResult();
- public abstract void setDescription(String description);
+ public abstract List getParameters();
- public abstract void setResult(String result);
+ public abstract String getParameterString();
- public abstract void setParameters(List parameters);
+ public abstract int getMinParamCount();
- public abstract void addParameter(String parameter);
-
- public abstract void setMinParamCount(int count);
-
- public abstract void setMaxParamCount(int count);
-
- public abstract void setTimestamp(long timestamp);
+ public abstract int getMaxParamCount();
-}
\ No newline at end of file
+ public abstract long getTimestamp();
+
+ /**
+ * Returns a enumeration of the paramteres, converted into a space
+ * seperated string.
+ *
+ * @return String with space seperated String
+ */
+ public abstract void setDeviceName(String deviceName);
+
+ public abstract void setCommand(String command);
+
+ public abstract void setDescription(String description);
+
+ public abstract void setResult(String result);
+
+ public abstract void setParameters(List parameters);
+
+ public abstract void addParameter(String parameter);
+
+ public abstract void setMinParamCount(int count);
+
+ public abstract void setMaxParamCount(int count);
+
+ public abstract void setTimestamp(long timestamp);
+}
Added:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/DbMetadataConfiguration.java
Added:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/MetadataConfiguration.java
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -10,7 +10,6 @@
import org.perfsonar.base.exceptions.PerfSONARException;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
-
/**
* Interface to which device status statistics providers should adhere
*
@@ -20,53 +19,51 @@
*
*/
public interface StatusAdapterInterface {
-
- // ---------------------- interface methods
-
- /**
- * Interface method to query about the device specific command
available
- *
- * @return List All specific StatusCommands for the device
- */
- public abstract List getAvailableSpecificCommands() ;
-
- /**
- * Sets the list with all specific commands available for that device
- *
- * @param availableSpecificCommands
- */
- public abstract void setAvailableSpecificCommands(List
availableSpecificCommands) ;
- /**
- * Adds a specific command to the list of available specific commands
- *
- * @param command
- */
- public abstract void
addAvailableSpecificCommand(StatusCommandInterface command) ;
-
- /**
- * Searches for a command supported by the device matching the given
- * description
- *
- * @param description
- * @return StatusCommandInterface representing the desirec command
- */
- public abstract StatusCommandInterface getCommand(String description)
throws PerfSONARException;
-
- /**
- * Executes the provided command on the remote device
- *
- *
- * @param command The StatusCommand to be executed command
- * @return StatusCommand with the results inserted
- */
- public abstract StatusCommandInterface
executeCommand(StatusCommandInterface command) ;
-
- /**
- * Makes the Adapter connecting to the device
- *
- */
- public abstract void connect() ;
-
- //List of commands that should be available to all status MP to be
included below
+ // ---------------------- interface methods
+ /**
+ * Interface method to query about the device specific command available
+ *
+ * @return List All specific StatusCommands for the device
+ */
+ public abstract List getAvailableSpecificCommands();
+
+ /**
+ * Sets the list with all specific commands available for that device
+ *
+ * @param availableSpecificCommands
+ */
+ public abstract void setAvailableSpecificCommands(List
availableSpecificCommands);
+
+ /**
+ * Adds a specific command to the list of available specific commands
+ *
+ * @param command
+ */
+ public abstract void addAvailableSpecificCommand(StatusCommandInterface
command);
+
+ /**
+ * Searches for a command supported by the device matching the given
+ * description
+ *
+ * @param description
+ * @return StatusCommandInterface representing the desirec command
+ */
+ public abstract StatusCommandInterface getCommand(String description)
throws PerfSONARException;
+
+ /**
+ * Executes the provided command on the remote device
+ *
+ *
+ * @param command The StatusCommand to be executed command
+ * @return StatusCommand with the results inserted
+ */
+ public abstract StatusCommandInterface
executeCommand(StatusCommandInterface command);
+
+ /**
+ * Makes the Adapter connecting to the device
+ *
+ */
+ public abstract void connect();
+ //List of commands that should be available to all status MP to be
included below
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,12 +20,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
@@ -43,609 +44,551 @@
*
*/
public class CiscoKeyStatusAdapter implements StatusAdapterInterface,
- ServiceEngine {
+ ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
- // TODO::Should be specified on a higher level -- on the Adapter level
+ // TODO::Should be specified on a higher level -- on the Adapter level
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoKeyStatusAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
-
- private String passphrase = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOKEYSTATUSADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoKeyStatusAdapter] Constructor finished");
- // ---------------------- constructors
+ }// CiscoKeyStatusAdapter
- public CiscoKeyStatusAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[CiscoKeyStatusAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[CiscoKeyStatusAdapter] setAvailableSpecificCommand
called");
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoKeyStatusAdapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoKeyStatusAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoKeyStatusAdapter
+ logger.debug("[CiscoKeyStatusAdapter] getCommand called");
- // ---------------------- public methods
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[CiscoKeyStatusAdapter]
getAvailableSpecificCommands called");
+ command = (StatusCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoKeyStatusAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger
- .debug("[CiscoKeyStatusAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoKeyStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ logger.debug("[CiscoKeyStatusAdapter] executeCommand called");
- logger
- .debug("[CiscoKeyStatusAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- }// addAvailableSpecificCommand
+ manager.disconnect();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- logger.debug("[CiscoKeyStatusAdapter] getCommand called");
+ }// if
- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- while (it.hasNext()) {
+ }// executeCommand
+ public void connect() {
+ }
- command = (StatusCommand) it.next();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ logger.info("[CiscoKeyStatusAdapter] Connect called");
- logger.debug("[CiscoKeyStatusAdapter] Command
found");
- return command;
+ try {
- }
+ if (manager == null) {
- }// while
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- logger.error("[CiscoKeyStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ if (passphrase == null || passphrase.equals(""))
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+ }
- }// getCommand
+ logger.info("[CiscoKeyStatusAdapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ //if (passphrase == null || passphrase.equals("")) {
+ // manager.connect(username, keyUrl);
+ //} else {
+ // manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[CiscoKeyStatusAdapter] Login");
- logger.debug("[CiscoKeyStatusAdapter] executeCommand called");
+ } catch (Exception e) {
- if (manager != null) {
+ logger.error("[CiscoKeyStatusAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ }
- manager.disconnect();
+ }// connect
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ // ---------------------- field methods
+ public int getPort() {
- }// if
+ return port;
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ }
- }// executeCommand
+ public void setPort(int port) {
- public void connect() {
- }
+ this.port = port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[CiscoKeyStatusAdapter] Connect called");
+ public String getPrompt() {
- try {
+ return prompt;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public void setPrompt(String prompt) {
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ this.prompt = prompt;
- }
+ }
- logger.info("[CiscoKeyStatusAdapter] Trying to
connect");
+ public String getUrl() {
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[CiscoKeyStatusAdapter] Login");
+ return url;
- } catch (Exception e) {
+ }
- logger
- .info("[CiscoKeyStatusAdapter] Error
occuring while connecting");
- logger.info(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ public void setUrl(String url) {
- }
+ this.url = url;
- }// connect
+ }
- // ---------------------- field methods
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- public int getPort() {
+ logger.debug("[CiscoKeyStatusAdapter] Configuring available
operations ...");
- return port;
+ Iterator commands = null;
+ String token = null;
- }
+ try {
- public void setPort(int port) {
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- this.port = port;
+ token = (String) commands.next();
+ if (token.contains("STATUS_")) {
- }
+ StatusCommand command = new StatusCommand(token,
properties.getProperty(subject, token, "commands"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- return prompt;
+ }
- }
+ }
- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {
- this.prompt = prompt;
+ logger.error("[CISCOKEYSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- }
+ }
- public String getUrl() {
+ logger.debug("[CiscoKeyStatusAdapter] Available operations
configured");
- return url;
+ }
- }
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp,
+ StatusCommandInterface statusCommand) {
- public void setUrl(String url) {
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- this.url = url;
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- }
+ }
- // ---------------------- Private methods
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- logger
- .debug("[CiscoKeyStatusAdapter] Configuring
available operations ...");
+ StringBuffer resultBuffer = new StringBuffer(t2);
- StringTokenizer tokenizer = null;
- String token = null;
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- try {
+ t2 = resultBuffer.toString();
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ return t2.replace("" + prompt, "---END---");
- token = tokenizer.nextToken();
- if (token.contains("STATUS_")) {
+ }
- StatusCommand command = new
StatusCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- }
+ }
- } catch (PerfSONARException e) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ logger.info("[CiscoKeyStatusAdapter] Webservice takeAction call
received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- logger
- .debug("[CiscoKeyStatusAdapter] Available
operations configured");
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp,
- StatusCommandInterface statusCommand) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ //CiscoKeyStatusAdapter adapter = new CiscoKeyStatusAdapter();
- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ availableSpecificCommands = new ArrayList();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ try {
- StringBuffer resultBuffer = new StringBuffer(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {
- return t2.replace("" + prompt, "---END---");
+ logger.error("[CISCOKEYSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- }
+ } catch (PerfSONARException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOKEYSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ }
- return this.serviceEngineType;
+ logger.debug("[CiscoKeyStatusAdapter] TelnetManager created: " + url
+ " " + port);
- }
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
- logger
- .info("[CiscoKeyStatusAdapter] Webservice
takeAction call received");
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ }
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {
- CiscoKeyStatusAdapter adapter = new CiscoKeyStatusAdapter();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- //adapter.connect(subject);
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- availableSpecificCommands = new ArrayList();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- username = properties.getProperty("service.r.mp." +
subject
- + ".username");
- keyUrl = properties.getProperty("service.r.mp." +
subject
- + ".keyUrl");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ }
- } catch (PerfSONARException e1) {
+ if (temp.equalsIgnoreCase("")) {
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- }
+ }
- logger.debug("[CiscoKeyStatusAdapter] TelnetManager created:
" + url
- + " " + port);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ } else if (statusCommand.getMinParamCount() == 0) {
- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- statusCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- if (statusCommand.getParameters().size() >=
statusCommand
- .getMinParamCount()
- &&
statusCommand.getParameters().size() <= statusCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand
= (StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ }
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (statusCommand.getMinParamCount() == 0) {
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand =
(StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ } else {
- } else {
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ }
- }
+ logger.info("[CiscoKeyStatusAdapter] Command executed succesfully");
- logger.info("[CiscoKeyStatusAdapter] Command executed
succesfully");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoKeyStatusAdapter] Constructing response message");
- logger.info("[CiscoKeyStatusAdapter] Constructing response
message");
+ Message response = new Message();
- Message response = new Message();
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ logger.info("[CiscoKeyStatusAdapter] takeAction finished");
- logger.info("[CiscoKeyStatusAdapter] takeAction finished");
+ return response;
- return response;
+ }
- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- // ---------------------- Stand-alond Test Method
+ try {
+ CiscoKeyStatusAdapter adapter = new CiscoKeyStatusAdapter();
- public static void main(String[] args) {
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("junipernl");
- try {
- CiscoKeyStatusAdapter adapter = new
CiscoKeyStatusAdapter();
+ adapter.connect("junipernl");
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ StatusCommandInterface statusCommand;
- adapter.connect("junipernl");
+ try {
- StatusCommandInterface statusCommand;
+ statusCommand = adapter.getCommand("STATUS_TEST");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- try {
+ //System.out.println(adapter.filterResult(temp, statusCommand));
- statusCommand =
adapter.getCommand("STATUS_TEST");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ } catch (PerfSONARException e) {
- System.out.println(adapter.filterResult(temp,
statusCommand));
+ //e.printStackTrace();
- } catch (PerfSONARException e) {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,18 +1,22 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Provider.Service;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
+import java.util.Set;
+import javax.swing.SwingUtilities;
+
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
import org.ggf.ns.nmwg.base.v2_0.EventType;
@@ -24,12 +28,15 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
+
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
@@ -47,603 +54,547 @@
*/
public class CiscoSshStatusAdapter implements StatusAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoSshStatusAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOSSHSTATUSADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoSshStatusAdapter] Constructor started");
- // ---------------------- constructors
+ logger.debug("[CiscoSshStatusAdapter] Constructor finished");
- public CiscoSshStatusAdapter() throws PerfSONARException {
+ }// CiscoSshStatusAdapter
- try {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.debug("[CiscoSshStatusAdapter] getAvailableSpecificCommands
called");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return availableSpecificCommands;
- try {
- properties.getProperties().store(new
FileOutputStream("eend.properties"), "");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoSshStatusAdapter] setAvailableSpecificCommand
called");
- } catch (PerfSONARException e) {
+ this.availableSpecificCommands = availableSpecificCommands;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {
- }
+ logger.debug("[CiscoSshStatusAdapter] addAvailableSpecificCommand
called");
- logger.debug("[CiscoSshStatusAdapter] Constructor started");
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoSshStatusAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoSshStatusAdapter
+ logger.debug("[CiscoSshStatusAdapter] getCommand called");
- // ---------------------- public methods
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[CiscoSshStatusAdapter]
getAvailableSpecificCommands called");
+ command = (StatusCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoSshStatusAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[CiscoSshStatusAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoSshStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ logger.debug("[CiscoSshStatusAdapter] executeCommand called");
- logger.debug("[CiscoSshStatusAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- }// addAvailableSpecificCommand
+ }// if
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshStatusAdapter] executeCommand finished");
+ return command;
- logger.debug("[CiscoSshStatusAdapter] getCommand called");
+ }// executeCommand
+ public void connect() {
+ }
- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- while (it.hasNext()) {
+ logger.info("[CiscoSshStatusAdapter] Connect called");
- command = (StatusCommand) it.next();
+ try {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {
- logger.debug("[CiscoSshStatusAdapter] Command
found");
- return command;
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ //System.out.println(username);
+
//System.out.println(PasswordEncryptor.decryptPassword(password));
+ //System.out.println(url);
- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- logger.error("[CiscoSshStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }
- }// getCommand
+ logger.info("[CiscoSshStatusAdapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[CiscoSshStatusAdapter] executeCommand called");
+ logger.info("[CiscoSshStatusAdapter Login");
- if (manager != null) {
+ } catch (Exception e) {
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[CiscoSshStatusAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshStatusAdapter] executeCommand
finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[CiscoSshStatusAdapter] Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
-
- //System.out.println(username);
- //System.out.println(password);
+ public String getPrompt() {
- manager = new SshManager(url, username,
password, false);
+ return prompt;
- }
+ }
- logger.info("[CiscoSshStatusAdapter] Trying to
connect");
+ public void setPrompt(String prompt) {
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;
- logger.info("[CiscoSshStatusAdapter Login");
+ }
- } catch (Exception e) {
+ public String getUrl() {
- logger.error("[CiscoSshStatusAdapter] Error occuring
while connecting");
- //System.err.println("[CiscoSshStatusAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ return url;
- }
+ }
- }// connect
+ public void setUrl(String url) {
- // ---------------------- field methods
+ this.url = url;
- public int getPort() {
+ }
- return port;
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- }
+ logger.debug("[CiscoSshStatusAdapter] Configuring available
operations ...");
- public void setPort(int port) {
+ Iterator commands = null;
+ String token = null;
- this.port = port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public String getPrompt() {
+ token = (String) commands.next();
+ if (token.contains("STATUS")) {
- return prompt;
+ StatusCommand command = new StatusCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSSHSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public String getUrl() {
+ logger.error("[CISCOSSHSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- return url;
+ }
- }
+ logger.debug("[CiscoSshStatusAdapter] Available operations
configured");
- public void setUrl(String url) {
+ }
- this.url = url;
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, StatusCommandInterface
statusCommand) {
- }
+ //logger.debug("result: " + temp);
+
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- // ---------------------- Private methods
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ }
- logger.debug("[CiscoSshStatusAdapter] Configuring available
operations ...");
+ //String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());
- StringTokenizer tokenizer = null;
- String token = null;
+ String t1 = temp.replaceAll("\\n", "");
+ String t2 = t1.replaceAll("\\r", "@@@");
+
+ StringBuffer resultBuffer = new StringBuffer(t2);
- try {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ t2 = resultBuffer.toString();
- token = tokenizer.nextToken();
- if (token.contains("STATUS")) {
+ return t2.replace("" + prompt, "---END---");
- StatusCommand command = new
StatusCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- } catch (PerfSONARException e) {
+ }
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- }
+ logger.info("[CiscoSshStatusAdapter] Webservice takeAction call
received");
- logger.debug("[CiscoSshStatusAdapter] Available operations
configured");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- }
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, StatusCommandInterface
statusCommand) {
+ logger.debug("SUBJECTSTRING: " + subject);
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ //CiscoSshStatusAdapter adapter = new CiscoSshStatusAdapter();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ // REPLACED
- StringBuffer resultBuffer = new StringBuffer(t2);
+ availableSpecificCommands = new ArrayList();
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ try {
- t2 = resultBuffer.toString();
+ url = properties.getProperty(subject, "url");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- return t2.replace("" + prompt, "---END---");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- }
+ } catch (NumberFormatException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOSSHSTATUSADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (PerfSONARException e1) {
- return this.serviceEngineType;
+ logger.error("[CISCOSSHSTATUSADAPTER][TakeAction]" +
e1.getStackTrace()[0].toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- }
+ }
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- logger.info("[CiscoSshStatusAdapter] Webservice takeAction
call received");
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ //
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- CiscoSshStatusAdapter adapter = new CiscoSshStatusAdapter();
- //adapter.connect(subject);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- // REPLACED
+ }
- availableSpecificCommands = new ArrayList();
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {
- try {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- } catch (NumberFormatException e1) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- } catch (PerfSONARException e1) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ }
- }
+ }
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ if (temp.equalsIgnoreCase("")) {
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- //
+ }
- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ } else if (statusCommand.getMinParamCount() == 0) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- statusCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- if (statusCommand.getParameters().size() >=
statusCommand
- .getMinParamCount()
- &&
statusCommand.getParameters().size() <= statusCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand
= (StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (statusCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand =
(StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ if (temp.equalsIgnoreCase("")) {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ } else {
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- logger.info("[CiscoSshStatusAdapter] Command executed
succesfully");
+ }
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoSshStatusAdapter] Command executed succesfully");
- logger.info("[CiscoSshStatusAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- Message response = new Message();
+ logger.info("[CiscoSshStatusAdapter] Constructing response message");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Message response = new Message();
- logger.info("[CiscoSshStatusAdapter] takeAction finished");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- return response;
+ logger.info("[CiscoSshStatusAdapter] takeAction finished");
- }
+ return response;
- // ---------------------- Stand-alond Test Method
+ }
- public static void main(String[] args) {
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- try {
- CiscoSshStatusAdapter adapter = new
CiscoSshStatusAdapter();
+ try {
+ CiscoSshStatusAdapter adapter = new CiscoSshStatusAdapter();
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco2");
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco2");
- adapter.connect("cisco2");
+ adapter.connect("cisco2");
- StatusCommandInterface statusCommand;
+ StatusCommandInterface statusCommand;
- try {
+ try {
- statusCommand =
adapter.getCommand("STATUS_INTERFACE");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ statusCommand = adapter.getCommand("STATUS_INTERFACE");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e) {
- e.printStackTrace();
+ //e.printStackTrace();
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,12 +20,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
@@ -43,644 +44,592 @@
*
*/
public class CiscoStatusAdapter implements StatusAdapterInterface,
- ServiceEngine {
+ ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default cisco-shell variables
+ // ---------------------- default cisco-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public CiscoStatusAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[CISCOSTATUSADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoStatusAdapter] Constructor finished");
- // ---------------------- constructors
+ }// CiscoStatusAdapter
- public CiscoStatusAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[CiscoStatusAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * *
+ *
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoStatusAdapter] setAvailableSpecificCommand
called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoStatusAdapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[CiscoStatusAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// CiscoStatusAdapter
+ logger.debug("[CiscoStatusAdapter] getCommand called");
- // ---------------------- public methods
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[CiscoStatusAdapter]
getAvailableSpecificCommands called");
+ command = (StatusCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[CiscoStatusAdapter] Command found");
+ return command;
- /**
- * *
- *
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[CiscoStatusAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ logger.debug("[CiscoStatusAdapter] executeCommand called");
- logger.debug("[CiscoStatusAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[CiscoStatusAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoStatusAdapter] executeCommand finished");
+ return command;
- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (StatusCommand) it.next();
+ logger.debug("[CiscoStatusAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[CiscoStatusAdapter] Command
found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ logger.debug("[CiscoStatusAdapter] url: " + url);
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ logger.debug("[CiscoStatusAdapter] port: " + port);
+ prompt = properties.getProperty(subject, "prompt");
+ logger.debug("[CiscoStatusAdapter] prompt: " + prompt);
+ username = properties.getProperty(subject, "username");
+ logger.debug("[CiscoStatusAdapter] username: " + username);
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ logger.debug("[CiscoStatusAdapter] cache: " + caching);
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- logger.error("[CiscoStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }
- }// getCommand
+ logger.debug("[CiscoStatusAdapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[CiscoStatusAdapter] executeCommand called");
+ logger.debug("[CiscoStatusAdapter] Login");
- if (manager != null) {
+ } catch (Exception e) {
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
+ logger.error("[CiscoStatusAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }
- }// if
+ }// connect
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoStatusAdapter] executeCommand finished");
- return command;
+ // ---------------------- field methods
+ public int getPort() {
- }// executeCommand
+ return port;
- public void connect() {
- }
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public void setPort(int port) {
- logger.debug("[CiscoStatusAdapter] Connect called");
+ this.port = port;
- try {
+ }
- if (manager == null) {
+ public String getPrompt() {
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- logger.debug("[CiscoStatusAdapter] url: "+
url);
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- logger.debug("[CiscoStatusAdapter] port: "+
port);
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- logger.debug("[CiscoStatusAdapter] prompt: "+
prompt);
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- logger.debug("[CiscoStatusAdapter] username:
"+ username);
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
- logger.debug("[CiscoStatusAdapter] cache: "+
caching);
+ return prompt;
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ }
- }
+ public void setPrompt(String prompt) {
- logger.debug("[CiscoStatusAdapter] Trying to
connect");
+ this.prompt = prompt;
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }
- logger.debug("[CiscoStatusAdapter] Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger
- .error("[CiscoStatusAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[CiscoStatusAdapter] Configuring available operations
...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("STATUS_")) {
- public String getPrompt() {
+ StatusCommand command = new StatusCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[CISCOSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[CISCOSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_WHO, "who"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_LIST, "list"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_HISTORY, "show history"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_DEBUG, "show debugging
zebra"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_LOGGING, "show logging"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_MEMORY, "show memory"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_CPU, "show thread cpu"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_VERSION, "show version"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_INTERFACE, "show interface"));
- }
+ logger.debug("[CiscoStatusAdapter] Available operations configured");
- public void setUrl(String url) {
+ }
- this.url = url;
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp,
+ StatusCommandInterface statusCommand) {
- }
+ //logger.debug("[CiscoStatusAdapter][filterResult] result: " + temp);
+
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- // ---------------------- Private methods
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ //logger.debug("[CiscoStatusAdapter][filterResult] temp1: " +
temp1);
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ //logger.debug("[CiscoStatusAdapter][filterResult] temp2: " +
temp2);
+ temp = temp1 + temp2;
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ }
- logger
- .debug("[CiscoStatusAdapter] Configuring
available operations ...");
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());
+ //logger.debug("[CiscoStatusAdapter][filterResult] tempResult: " +
tempResult);
+
+ String t1 = tempResult.replaceAll("\\n", "");
+ //logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ //logger.debug(t2);
- StringTokenizer tokenizer = null;
- String token = null;
+ StringBuffer resultBuffer = new StringBuffer(t2);
- try {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ t2 = resultBuffer.toString();
- token = tokenizer.nextToken();
- if (token.contains("STATUS_")) {
+ return t2.replace("" + prompt, "---END---");
- StatusCommand command = new
StatusCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- }
+ logger.info("[CiscoStatusAdapter] Webservice takeAction call
received");
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_WHO, "who"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_LIST, "list"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_HISTORY, "show
history"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_DEBUG, "show debugging
zebra"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_LOGGING, "show
logging"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_MEMORY, "show memory"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_CPU, "show thread
cpu"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_VERSION, "show
version"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_INTERFACE, "show
interface"));
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- logger.debug("[CiscoStatusAdapter] Available operations
configured");
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp,
- StatusCommandInterface statusCommand) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ CiscoStatusAdapter adapter = new CiscoStatusAdapter();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ // REPLACED
- }
+ availableSpecificCommands = new ArrayList();
- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ try {
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new TelnetManager(url, port, false, timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ } catch (NumberFormatException e1) {
- t2 = resultBuffer.toString();
+ logger.error("[CISCOSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return t2.replace("" + prompt, "---END---");
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[CISCOSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // ---------------------- Methods from service engine interface
+ }
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.debug("[CiscoStatusAdapter] TelnetManager created: " + url +
" " + port);
- return this.serviceEngineType;
+ try {
- }
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ } catch (PerfSONARException e) {
- logger.info("[CiscoStatusAdapter] Webservice takeAction call
received");
+ logger.error("[CISCOSTATUSADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ }
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ logger.debug("[CiscoStatusAdapter] Prompt set in TelnetManager: " +
prompt);
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- CiscoStatusAdapter adapter = new CiscoStatusAdapter();
- //adapter.connect(subject);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- // REPLACED
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- availableSpecificCommands = new ArrayList();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- try {
+ }
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {
- manager = new TelnetManager(url, port, false);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- } catch (NumberFormatException e1) {
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- } catch (PerfSONARException e1) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ }
- try {
+ }
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ if (temp.equalsIgnoreCase("")) {
- } catch (PerfSONARException e) {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ }
- }
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- logger.debug("[CiscoStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ } else if (statusCommand.getMinParamCount() == 0) {
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- statusCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- if (statusCommand.getParameters().size() >=
statusCommand
- .getMinParamCount()
- &&
statusCommand.getParameters().size() <= statusCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand
= (StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();
- } else if (statusCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand =
(StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[CiscoStatusAdapter] Command executed succesfully");
- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[CiscoStatusAdapter] Command executed
succesfully");
+ logger.info("[CiscoStatusAdapter] Constructing response message");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ Message response = new Message();
- logger.info("[CiscoStatusAdapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });
- // System.err.println(respMetaData);
- // System.err.println(respData);
+ logger.info("[CiscoStatusAdapter] takeAction finished");
- // response.setSonarMetadata(request.getSonarMetadata());
- // response.setSonarData(new Data[] { data });
+ return response;
+ // return new ServiceEngineResponse();
- logger.info("[CiscoStatusAdapter] takeAction finished");
+ }
- return response;
- // return new ServiceEngineResponse();
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ CiscoStatusAdapter adapter = new CiscoStatusAdapter();
- // ---------------------- Stand-alond Test Method
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("cisco1");
- public static void main(String[] args) {
+ adapter.connect("cisco1");
- try {
- CiscoStatusAdapter adapter = new CiscoStatusAdapter();
+ StatusCommandInterface statusCommand;
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("cisco1");
+ try {
- adapter.connect("cisco1");
+ statusCommand = adapter.getCommand("STATUS_WHO");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- StatusCommandInterface statusCommand;
+ } catch (PerfSONARException e) {
- try {
+ //e.printStackTrace();
- statusCommand =
adapter.getCommand("STATUS_WHO");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- System.out.println(temp);
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,12 +20,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
@@ -43,621 +44,565 @@
*
*/
public class JuniperKeyStatusAdapter implements StatusAdapterInterface,
- ServiceEngine {
+ ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
- // TODO::Should be specified on a higher level -- on the Adapter level
+ // TODO::Should be specified on a higher level -- on the Adapter level
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String keyUrl = "";
+ private String passphrase = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperKeyStatusAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String keyUrl = "";
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- private String passphrase = "";
-
- private int caching = 0;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- // ---------------------- class-fields
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ } catch (PerfSONARException e) {
- private RemoteManager manager = null;
+ logger.error("[JUNIPERKEYSTATUSADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private LoggerComponent logger = null;
+ }
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[JuniperKeyStatusAdapter] Constructor finished");
- private static List cachedResults = new ArrayList();
+ }// JuniperKeyStatusAdapter
- // ---------------------- constructors
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- public JuniperKeyStatusAdapter() throws PerfSONARException {
+ logger.debug("[JuniperKeyStatusAdapter] getAvailableSpecificCommands
called");
- try {
+ return availableSpecificCommands;
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ logger.debug("[JuniperKeyStatusAdapter] setAvailableSpecificCommand
called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {
- } catch (PerfSONARException e) {
+ logger.debug("[JuniperKeyStatusAdapter] addAvailableSpecificCommand
called");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ availableSpecificCommands.add(command);
- }
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {
- logger.debug("[JuniperKeyStatusAdapter] Constructor
finished");
+ logger.debug("[JuniperKeyStatusAdapter] getCommand called");
- }// JuniperKeyStatusAdapter
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- // ---------------------- public methods
+ while (it.hasNext()) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ command = (StatusCommand) it.next();
- logger
- .debug("[JuniperKeyStatusAdapter]
getAvailableSpecificCommands called");
+ if (command.getDescription().equalsIgnoreCase(description)) {
- return availableSpecificCommands;
+ logger.debug("[JuniperKeyStatusAdapter] Command found");
+ return command;
- }// getAvailableSpecificCommands
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while
- logger
- .debug("[JuniperKeyStatusAdapter]
setAvailableSpecificCommand called");
+ logger.error("[JuniperKeyStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- this.availableSpecificCommands = availableSpecificCommands;
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
- }// setAvailableSpecificCommands
+ logger.debug("[JuniperKeyStatusAdapter] executeCommand called");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ if (manager != null) {
- logger
- .debug("[JuniperKeyStatusAdapter]
addAvailableSpecificCommand called");
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
- availableSpecificCommands.add(command);
+ manager.disconnect();
- }// addAvailableSpecificCommand
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if
- logger.debug("[JuniperKeyStatusAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }
- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- command = (StatusCommand) it.next();
+ logger.info("[JuniperKeyStatusAdapter] Connect called");
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {
- logger.debug("[JuniperKeyStatusAdapter]
Command found");
- return command;
+ if (manager == null) {
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }// while
+ if (passphrase == null || passphrase.equals(""))
+ manager = new SshKeyManager(url, username, keyUrl,
false, timeout);
+ else manager = new SshKeyManager(url, username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase), false, timeout);
+ }
- logger.error("[JuniperKeyStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[JuniperKeyStatusAdapter] Trying to connect");
- }// getCommand
+ //if (passphrase == null || passphrase.equals("")) {
+ // manager.connect(username, keyUrl);
+ //} else {
+ // manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ //}
+ logger.info("[JuniperKeyStatusAdapter] Login");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ } catch (Exception e) {
- logger.debug("[JuniperKeyStatusAdapter] executeCommand
called");
+ logger.error("[JuniperKeyStatusAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- if (manager != null) {
+ }
- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ }// connect
- manager.disconnect();
+ // ---------------------- field methods
+ public int getPort() {
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ return port;
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ public void setPort(int port) {
- }// executeCommand
+ this.port = port;
- public void connect() {
- }
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public String getPrompt() {
- logger.info("[JuniperKeyStatusAdapter] Connect called");
+ return prompt;
- try {
+ }
- if (manager == null) {
+ public void setPrompt(String prompt) {
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- keyUrl =
properties.getProperty("service.r.mp." + subject
- + ".keyUrl");
- passphrase =
properties.getProperty("service.r.mp." + subject
- + ".passphrase");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ this.prompt = prompt;
- manager = new SshKeyManager(url, username,
keyUrl, false);
+ }
- }
+ public String getUrl() {
- logger.info("[JuniperKeyStatusAdapter] Trying to
connect");
+ return url;
- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[JuniperKeyStatusAdapter] Login");
+ }
- } catch (Exception e) {
+ public void setUrl(String url) {
- logger
- .info("[JuniperKeyStatusAdapter]
Error occuring while connecting");
- logger.info(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ this.url = url;
- }
+ }
- }// connect
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- // ---------------------- field methods
+ logger.debug("[JuniperKeyStatusAdapter] Configuring available
operations ...");
- public int getPort() {
+ Iterator commands = null;
+ String token = null;
- return port;
+ try {
- }
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- public void setPort(int port) {
+ token = (String) commands.next();
+ if (token.contains("STATUS")) {
- this.port = port;
+ StatusCommand command = new StatusCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERKEYSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- public String getPrompt() {
+ }
- return prompt;
+ }
- }
+ } catch (PerfSONARException e) {
- public void setPrompt(String prompt) {
+ logger.error("[JUNIPERKEYSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- this.prompt = prompt;
+ }
- }
+ logger.debug("[JuniperKeyStatusAdapter] Available operations
configured");
- public String getUrl() {
+ }
- return url;
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp,
+ StatusCommandInterface statusCommand) {
- }
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- public void setUrl(String url) {
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- this.url = url;
+ }
- }
+ while (temp.indexOf("---(more") > -1) {
- // ---------------------- Private methods
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ }
- logger
- .debug("[JuniperKeyStatusAdapter] Configuring
available operations ...");
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- StringTokenizer tokenizer = null;
- String token = null;
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- try {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- token = tokenizer.nextToken();
- if (token.contains("STATUS")) {
+ t2 = resultBuffer.toString();
- StatusCommand command = new
StatusCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ return t2.replace("" + prompt, "---END---");
- }
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- } catch (PerfSONARException e) {
+ return this.serviceEngineType;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- logger
- .debug("[JuniperKeyStatusAdapter] Available
operations configured");
+ logger.info("[JuniperKeyStatusAdapter] Webservice takeAction call
received");
- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp,
- StatusCommandInterface statusCommand) {
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.debug("SUBJECTSTRING: " + subject);
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- }
- while (temp.indexOf("---(more") > -1) {
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ //JuniperKeyStatusAdapter adapter = new JuniperKeyStatusAdapter();
- }
+ availableSpecificCommands = new ArrayList();
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ try {
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new SshKeyManager(url, username, keyUrl, false,
timeout);
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ } catch (NumberFormatException e1) {
- t2 = resultBuffer.toString();
+ logger.error("[JUNIPERKEYSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- return t2.replace("" + prompt, "---END---");
+ } catch (PerfSONARException e1) {
- }
+ logger.error("[JUNIPERKEYSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- // ---------------------- Methods from service engine interface
+ }
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.debug("[JuniperKeyStatusAdapter] TelnetManager created: " +
url + " " + port);
- return this.serviceEngineType;
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- }
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- logger
- .info("[JuniperKeyStatusAdapter] Webservice
takeAction call received");
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ }
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- JuniperKeyStatusAdapter adapter = new
JuniperKeyStatusAdapter();
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- //adapter.connect(subject);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- availableSpecificCommands = new ArrayList();
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- username = properties.getProperty("service.r.mp." +
subject
- + ".username");
- keyUrl = properties.getProperty("service.r.mp." +
subject
- + ".keyUrl");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- manager = new SshKeyManager(url, username, keyUrl,
false);
+ }
- } catch (NumberFormatException e1) {
+ }
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (temp.equalsIgnoreCase("")) {
- } catch (PerfSONARException e1) {
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ }
- }
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- logger.debug("[JuniperKeyStatusAdapter] TelnetManager
created: " + url
- + " " + port);
+ } else if (statusCommand.getMinParamCount() == 0) {
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- statusCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- }
+ }
- if (statusCommand.getParameters().size() >=
statusCommand
- .getMinParamCount()
- &&
statusCommand.getParameters().size() <= statusCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand
= (StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ }
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ if (temp.equalsIgnoreCase("")) {
- } else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- } else if (statusCommand.getMinParamCount() == 0) {
+ }
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand =
(StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ } else {
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- } else {
+ }
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ logger.info("[JuniperKeyStatusAdapter] Command executed
succesfully");
- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[JuniperKeyStatusAdapter] Command executed
succesfully");
+ logger.info("[JuniperKeyStatusAdapter] Constructing response
message");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ Message response = new Message();
- logger.info("[JuniperKeyStatusAdapter] Constructing response
message");
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- Message response = new Message();
+ logger.info("[JuniperKeyStatusAdapter] takeAction finished");
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ return response;
- logger.info("[JuniperKeyStatusAdapter] takeAction finished");
+ }
- return response;
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- }
+ try {
+ JuniperKeyStatusAdapter adapter = new JuniperKeyStatusAdapter();
- // ---------------------- Stand-alond Test Method
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("junipernl");
- public static void main(String[] args) {
+ adapter.connect("junipernl");
- try {
- JuniperKeyStatusAdapter adapter = new
JuniperKeyStatusAdapter();
+ StatusCommandInterface statusCommand;
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ try {
- adapter.connect("junipernl");
+ statusCommand = adapter.getCommand("STATUS_TEST");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- StatusCommandInterface statusCommand;
+ //System.out.println(adapter.filterResult(temp, statusCommand));
- try {
+ } catch (PerfSONARException e) {
- statusCommand =
adapter.getCommand("STATUS_TEST");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //e.printStackTrace();
- System.out.println(adapter.filterResult(temp,
statusCommand));
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,12 +20,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
@@ -44,607 +45,559 @@
*/
public class JuniperSshStatusAdapter implements StatusAdapterInterface,
ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperSshStatusAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private List availableSpecificCommands = null;
+ //FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[JUNIPERSSHSTATUSADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperSshStatusAdapter] Constructor started");
- // ---------------------- constructors
+ logger.debug("[JuniperSshStatusAdapter] Constructor finished");
- public JuniperSshStatusAdapter() throws PerfSONARException {
+ }// JuniperSshStatusAdapter
- try {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.debug("[JuniperSshStatusAdapter] getAvailableSpecificCommands
called");
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ return availableSpecificCommands;
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[JuniperSshStatusAdapter] setAvailableSpecificCommand
called");
- } catch (PerfSONARException e) {
+ this.availableSpecificCommands = availableSpecificCommands;
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {
- }
+ logger.debug("[JuniperSshStatusAdapter] addAvailableSpecificCommand
called");
- logger.debug("[JuniperSshStatusAdapter] Constructor started");
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperSshStatusAdapter] Constructor
finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// JuniperSshStatusAdapter
+ logger.debug("[JuniperSshStatusAdapter] getCommand called");
- // ---------------------- public methods
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger.debug("[JuniperSshStatusAdapter]
getAvailableSpecificCommands called");
+ command = (StatusCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[JuniperSshStatusAdapter] Command found");
+ return command;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger.debug("[JuniperSshStatusAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperSshStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ logger.debug("[JuniperSshStatusAdapter] executeCommand called");
- logger.debug("[JuniperSshStatusAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- }// addAvailableSpecificCommand
+ }// if
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperSshStatusAdapter] executeCommand finished");
+ return command;
- logger.debug("[JuniperSshStatusAdapter] getCommand called");
+ }// executeCommand
+ public void connect() {
+ }
- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- while (it.hasNext()) {
+ logger.info("[JuniperSshStatusAdapter] Connect called");
- command = (StatusCommand) it.next();
+ try {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {
- logger.debug("[JuniperSshStatusAdapter]
Command found");
- return command;
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- }
+ //System.out.println(username);
+ //System.out.println(password);
- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- logger.error("[JuniperSshStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }
- }// getCommand
+ logger.info("[JuniperSshStatusAdapter] Trying to connect");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ //manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[JuniperSshStatusAdapter] executeCommand
called");
+ logger.info("[JuniperSshStatusAdapter Login");
- if (manager != null) {
+ } catch (Exception e) {
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.error("[JuniperSshStatusAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- }// if
+ }
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperSshStatusAdapter] executeCommand
finished");
- return command;
+ }// connect
- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {
- public void connect() {
- }
+ return port;
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }
- logger.info("[JuniperSshStatusAdapter] Connect called");
+ public void setPort(int port) {
- try {
+ this.port = port;
- if (manager == null) {
+ }
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ public String getPrompt() {
- //System.out.println(username);
- //System.out.println(password);
+ return prompt;
- manager = new SshManager(url, username,
password, false);
+ }
- }
+ public void setPrompt(String prompt) {
- logger.info("[JuniperSshStatusAdapter] Trying to
connect");
+ this.prompt = prompt;
- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }
- logger.info("[JuniperSshStatusAdapter Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger.error("[JuniperSshStatusAdapter] Error
occuring while connecting");
- //System.err.println("[JuniperSshStatusAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- //System.err.println(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[JuniperSshStatusAdapter] Configuring available
operations ...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("STATUS_")) {
- public String getPrompt() {
+ StatusCommand command = new StatusCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSSHSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[JUNIPERSSHSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ logger.debug("[JuniperSshStatusAdapter] Available operations
configured");
- }
+ }
- public void setUrl(String url) {
+ /**
+ * This private method filters out any non-XML compliant characters from
+ * a String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp, StatusCommandInterface
statusCommand) {
- this.url = url;
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- }
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- // ---------------------- Private methods
+ }
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ while (temp.indexOf("---(more") > -1) {
- logger.debug("[JuniperSshStatusAdapter] Configuring available
operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- StringTokenizer tokenizer = null;
- String token = null;
+ }
- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);
- token = tokenizer.nextToken();
- if (token.contains("STATUS_")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);
- StatusCommand command = new
StatusCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
- }
+ return t2.replace("" + prompt, "---END---");
- } catch (PerfSONARException e) {
+ }
- //e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- }
+ return this.serviceEngineType;
- logger.debug("[JuniperSshStatusAdapter] Available operations
configured");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- /**
- * This private method filters out any non-XML compliant characters
from
- * a String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp, StatusCommandInterface
statusCommand) {
+ logger.info("[JuniperSshStatusAdapter] Webservice takeAction call
received");
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- while (temp.indexOf("---(more") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ //JuniperSshStatusAdapter adapter = new JuniperSshStatusAdapter();
- char c = 10;
- String t1 = tempResult.replaceAll("" + c, "@@@");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "");
- // System.err.println(t2);
+ // REPLACED
- StringBuffer resultBuffer = new StringBuffer(t2);
+ availableSpecificCommands = new ArrayList();
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ try {
- t2 = resultBuffer.toString();
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false, timeout);
- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {
- }
+ logger.error("[JUNIPERSSHSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- // ---------------------- Methods from service engine interface
+ } catch (PerfSONARException e1) {
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ logger.error("[JUNIPERSSHSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- return this.serviceEngineType;
+ }
- }
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);
- logger.info("[JuniperSshStatusAdapter] Webservice takeAction
call received");
+ //
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- //System.out.println("SUBJECTSTRING: " + subjectString);
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- JuniperSshStatusAdapter adapter = new
JuniperSshStatusAdapter();
- //adapter.connect(subject);
+ }
- // REPLACED
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {
- availableSpecificCommands = new ArrayList();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- try {
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- } catch (NumberFormatException e1) {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ }
- }
+ if (temp.equalsIgnoreCase("")) {
- logger.debug("[CiscoStatusAdapter] SshManager created: " +
url + " "
- + port);
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ }
- //
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ } else if (statusCommand.getMinParamCount() == 0) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- statusCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (statusCommand.getParameters().size() >=
statusCommand
- .getMinParamCount()
- &&
statusCommand.getParameters().size() <= statusCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand
= (StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (statusCommand.getMinParamCount() == 0) {
+ if (temp.equalsIgnoreCase("")) {
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand =
(StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ this.connect(subject);
+ temp = this.executeCommand(statusCommand).getResult();
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ }
- } else {
+ } else {
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- }
+ }
- logger.info("[JuniperSshStatusAdapter] Command executed
succesfully");
+ logger.info("[JuniperSshStatusAdapter] Command executed
succesfully");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[JuniperSshStatusAdapter] Constructing response
message");
+ logger.info("[JuniperSshStatusAdapter] Constructing response
message");
- Message response = new Message();
+ Message response = new Message();
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- logger.info("[JuniperSshStatusAdapter] takeAction finished");
+ logger.info("[JuniperSshStatusAdapter] takeAction finished");
- return response;
+ return response;
- }
+ }
- // ---------------------- Stand-alond Test Method
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- public static void main(String[] args) {
+ try {
+ JuniperSshStatusAdapter adapter = new JuniperSshStatusAdapter();
- try {
- JuniperSshStatusAdapter adapter = new
JuniperSshStatusAdapter();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("juniper2");
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("juniper2");
+ adapter.connect("juniper2");
- adapter.connect("juniper2");
+ StatusCommandInterface statusCommand;
- StatusCommandInterface statusCommand;
+ try {
- try {
+ statusCommand = adapter.getCommand("STATUS");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);
- statusCommand = adapter.getCommand("STATUS");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println(temp);
+ } catch (PerfSONARException e) {
- } catch (PerfSONARException e) {
+ //e.printStackTrace();
- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,6 +1,6 @@
/*
- * Created/Updated on Jul 14th, 2006
- * Version Number: 0.6
+ * Created/Updated on Jan 8th, 2009
+ * Version Number: 1.0
* Project: perfSONAR
*/
package
org.perfsonar.service.measurementPoint.lookingGlassType.status.adapters;
@@ -8,7 +8,6 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.StringTokenizer;
import org.ggf.ns.nmwg.base.v2_0.Data;
import org.ggf.ns.nmwg.base.v2_0.Datum;
@@ -21,12 +20,14 @@
import org.ggf.ns.nmwg.topology.v2_0.EndPoint;
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
-import
org.perfsonar.base.auxiliary.components.configuration.properties.PropertiesConfigurationComponent;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
import org.perfsonar.service.base.engine.ServiceEngine;
import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.ServicePropertiesConfigurator;
import
org.perfsonar.service.measurementPoint.lookingGlassType.engine.commands.ParameterChecker;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.DbMetadataConfiguration;
+import
org.perfsonar.service.measurementPoint.lookingGlassType.metadata.MetadataConfiguration;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommand;
import
org.perfsonar.service.measurementPoint.lookingGlassType.status.commands.StatusCommandInterface;
@@ -43,653 +44,592 @@
*
*/
public class JuniperStatusAdapter implements StatusAdapterInterface,
- ServiceEngine {
+ ServiceEngine {
- /**
- * Type of service angine.
- */
- private String serviceEngineType = null;
+ /**
+ * Type of service angine.
+ */
+ private String serviceEngineType = null;
- // ---------------------- default juniper-shell variables
+ // ---------------------- default juniper-shell variables
+ private String url = "";
+ private String prompt = "";
+ private int port = 0;
+ private String username = "";
+ private String password = "";
+ private int caching = 0;
+ private int timeout = 0;
- private String url = "";
+ // ---------------------- class-fields
+ private List availableSpecificCommands = null;
+ private RemoteManager manager = null;
+ private LoggerComponent logger = null;
+ private MetadataConfiguration properties = null;
+ // ---------------------- caching attributes
+ private static List cachedResults = new ArrayList();
- private String prompt = "";
+ // ---------------------- constructors
+ public JuniperStatusAdapter() throws PerfSONARException {
- private int port = 0;
+ try {
- private String username = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String password = "";
-
- private int caching = 0;
+ this.properties = new DbMetadataConfiguration();
+ properties.initStorage();
- // ---------------------- class-fields
+ // FOR LOCAL TESTING
+ availableSpecificCommands = new ArrayList();
- private List availableSpecificCommands = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
- private RemoteManager manager = null;
+ } catch (PerfSONARException e) {
- private LoggerComponent logger = null;
+ logger.error("[JUNIPERSTATUSADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");
- private PropertiesConfigurationComponent properties = null;
-
- // ---------------------- caching attributes
+ }
- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperStatusAdapter] Constructor finished");
- // ---------------------- constructors
+ }// JuniperStatusAdapter
- public JuniperStatusAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {
- try {
+ logger.debug("[JuniperStatusAdapter] getAvailableSpecificCommands
called");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;
- properties = (PropertiesConfigurationComponent)
AuxiliaryComponentManager
-
.getInstance().getComponent(ComponentNames.CONFIG);
+ }// getAvailableSpecificCommands
+ /**
+ * *
+ *
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[JuniperStatusAdapter] setAvailableSpecificCommand
called");
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;
- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[JuniperStatusAdapter] addAvailableSpecificCommand
called");
- }
+ availableSpecificCommands.add(command);
- logger.debug("[JuniperStatusAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {
- }// JuniperStatusAdapter
+ logger.debug("[JuniperStatusAdapter] getCommand called");
- // ---------------------- public methods
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ while (it.hasNext()) {
- logger
- .debug("[JuniperStatusAdapter]
getAvailableSpecificCommands called");
+ command = (StatusCommand) it.next();
- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {
- }// getAvailableSpecificCommands
+ logger.debug("[JuniperStatusAdapter] Command found");
+ return command;
- /**
- * *
- *
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }
- logger
- .debug("[JuniperStatusAdapter]
setAvailableSpecificCommand called");
+ }// while
- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");
- }// setAvailableSpecificCommands
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ logger.debug("[JuniperStatusAdapter] executeCommand called");
- logger
- .debug("[JuniperStatusAdapter]
addAvailableSpecificCommand called");
+ if (manager != null) {
- availableSpecificCommands.add(command);
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
- }// addAvailableSpecificCommand
+ String temp2 = manager.executeCommand(" ");
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());
- logger.debug("[JuniperStatusAdapter] getCommand called");
+ }// if
- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperStatusAdapter] executeCommand finished");
+ return command;
- while (it.hasNext()) {
+ }// executeCommand
+ public void connect() {
+ }
- command = (StatusCommand) it.next();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {
- if
(command.getDescription().equalsIgnoreCase(description)) {
+ logger.debug("[JuniperStatusAdapter] Connect called");
- logger.debug("[JuniperStatusAdapter] Command
found");
- return command;
+ try {
- }
+ if (manager == null) {
- }// while
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject,
"port"));
+ prompt = properties.getProperty(subject, "prompt");
+ username = properties.getProperty(subject, "username");
+ password = properties.getProperty(subject, "password");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- logger.error("[JuniperStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new TelnetManager(url, port, false, timeout);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- }// getCommand
+ }
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ logger.debug("[JuniperStatusAdapter] Trying to connect");
- logger.debug("[JuniperStatusAdapter] executeCommand called");
+ manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ logger.debug("[JuniperStatusAdapter] Login");
- if (manager != null) {
+ } catch (Exception e) {
- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ logger.error("[JuniperStatusAdapter] Error occuring while
connecting");
+ logger.error(e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.connect",
+ "Could not connect to underlying device");
- String temp2 = manager.executeCommand(" ");
+ }
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }// connect
- }// if
+ // ---------------------- field methods
+ public int getPort() {
- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ return port;
- }// executeCommand
+ }
- public void connect() {
- }
+ public void setPort(int port) {
- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;
- logger.debug("[JuniperStatusAdapter] Connect called");
+ }
- try {
+ public String getPrompt() {
- if (manager == null) {
+ return prompt;
- url = properties
- .getProperty("service.r.mp."
+ subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt =
properties.getProperty("service.r.mp." + subject
- + ".prompt");
- username =
properties.getProperty("service.r.mp." + subject
- + ".username");
- password =
properties.getProperty("service.r.mp." + subject
- + ".password");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ }
- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp."
+ subject + ".prompt"));
+ public void setPrompt(String prompt) {
- }
+ this.prompt = prompt;
- logger.debug("[JuniperStatusAdapter] Trying to
connect");
+ }
- manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[JuniperStatusAdapter] Login");
+ public String getUrl() {
- } catch (Exception e) {
+ return url;
- logger
- .error("[JuniperStatusAdapter] Error
occuring while connecting");
- logger.error(e.getStackTrace().toString());
- throw new
PerfSONARException("error.mp.sshtelnet.connect",
- "Could not connect to underlying
device");
+ }
- }
+ public void setUrl(String url) {
- }// connect
+ this.url = url;
- // ---------------------- field methods
+ }
- public int getPort() {
+ // ---------------------- Private methods
+ /**
+ * This private method adds all available commands for the device to the
+ * list of available commands
+ */
+ private void configureCommands(String subject) throws PerfSONARException
{
- return port;
+ logger.debug("[JuniperStatusAdapter] Configuring available
operations ...");
- }
+ Iterator commands = null;
+ String token = null;
- public void setPort(int port) {
+ try {
- this.port = port;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {
- }
+ token = (String) commands.next();
+ if (token.contains("STATUS_")) {
- public String getPrompt() {
+ logger.debug(properties.getProperty("service.mp." +
subject + ".commands." + token));
+ StatusCommand command = new StatusCommand(token,
properties.getProperty(subject, token, "command"));
+ try {
+ logger.debug("service.mp." + subject + ".commands."
+ token + ".minParamCount");
+ int minParamCount =
Integer.parseInt(properties.getProperty(subject, token, "minParamCount"));
+ command.setMinParamCount(minParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
+ try {
+ int maxParamCount =
Integer.parseInt(properties.getProperty(subject, token, "maxParamCount"));
+ command.setMaxParamCount(maxParamCount);
+ } catch (PerfSONARException e1) {
+
logger.error("[JUNIPERSTATUSADAPTER][ConfigureCommands]" +
e1.getStackTrace().toString());
+ }
- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);
- }
+ }
- public void setPrompt(String prompt) {
+ }
- this.prompt = prompt;
+ } catch (PerfSONARException e) {
- }
+ logger.error("[JUNIPERSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");
- public String getUrl() {
+ }
- return url;
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_WHO, "who"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_LIST, "list"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_HISTORY, "show history"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_DEBUG, "show debugging
zebra"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_LOGGING, "show logging"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_MEMORY, "show memory"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_CPU, "show thread cpu"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_VERSION, "show version"));
+ // this.addAvailableSpecificCommand(new
+ // StatusCommand(ActionType.MP_STATUS_INTERFACE, "show interface"));
- }
+ logger.debug("[JuniperStatusAdapter] Available operations
configured");
- public void setUrl(String url) {
+ }
- this.url = url;
+ /**
+ * This private method filters out any non-XML compliant characters from
a
+ * String
+ *
+ * @param temp
+ * @return String
+ */
+ private String filterResult(String temp,
+ StatusCommandInterface statusCommand) {
- }
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {
- // ---------------------- Private methods
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;
- /**
- * This private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ }
- logger
- .debug("[JuniperStatusAdapter] Configuring
available operations ...");
- // System.out.println("[JuniperStatusAdapter] Configuring
available
- // operations ...");
+ while (temp.indexOf("---(more") > 0) {
- StringTokenizer tokenizer = null;
- String token = null;
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;
- try {
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + subject
+ ".commands"), ",");
- while (tokenizer.hasMoreTokens()) {
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());
- token = tokenizer.nextToken();
- if (token.contains("STATUS_")) {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);
- //
System.out.println(properties.getProperty("service.mp."+subject+".commands."+token));
- StatusCommand command = new
StatusCommand(token, properties
-
.getProperty("service.mp." + subject + ".commands."
- +
token));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty("service.mp." + subject
-
+ ".commands." + token
-
+ ".maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
-
- command.setDeviceName(subject);
-
this.addAvailableSpecificCommand(command);
+ StringBuffer resultBuffer = new StringBuffer(t2);
- }
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }
- }
+ t2 = resultBuffer.toString();
+ logger.debug("PROMPT: " + prompt);
- } catch (PerfSONARException e) {
+ return t2.replace("" + prompt, "---END---");
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ }
- }
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_WHO, "who"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_LIST, "list"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_HISTORY, "show
history"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_DEBUG, "show debugging
zebra"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_LOGGING, "show
logging"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_MEMORY, "show memory"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_CPU, "show thread
cpu"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_VERSION, "show
version"));
- // this.addAvailableSpecificCommand(new
- // StatusCommand(ActionType.MP_STATUS_INTERFACE, "show
interface"));
+ return this.serviceEngineType;
- logger.debug("[JuniperStatusAdapter] Available operations
configured");
+ }
- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {
- /**
- * This private method filters out any non-XML compliant characters
from a
- * String
- *
- * @param temp
- * @return String
- */
- private String filterResult(String temp,
- StatusCommandInterface statusCommand) {
+ logger.info("[JuniperStatusAdapter] Webservice takeAction call
received");
- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();
- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();
- }
+ logger.debug("SUBJECTSTRING: " + subject);
- while (temp.indexOf("---(more") > 0) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();
+ //eventTypeString =
eventTypeString.substring(ServicePropertiesConfigurator.EVENTTYPE_PREFIX.length()-1,
eventTypeString.lastIndexOf("/"));
- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
- }
+ JuniperStatusAdapter adapter = new JuniperStatusAdapter();
- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ availableSpecificCommands = new ArrayList();
- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ try {
- StringBuffer resultBuffer = new StringBuffer(t2);
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));
+ timeout = Integer.parseInt(properties.getProperty(subject,
"timeout"));
- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ manager = new TelnetManager(url, port, false, timeout);
- t2 = resultBuffer.toString();
- System.out.println("PROMPT: " + prompt);
+ } catch (NumberFormatException e1) {
- return t2.replace("" + prompt, "---END---");
+ logger.error("[JUNIPERSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");
- }
+ } catch (PerfSONARException e1) {
- // ---------------------- Methods from service engine interface
+ logger.error("[JUNIPERSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");
- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ }
- return this.serviceEngineType;
+ logger.debug("[JuniperStatusAdapter] TelnetManager created: " + url
+ " " + port);
- }
+ try {
- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));
- logger
- .info("[JuniperStatusAdapter] Webservice
takeAction call received");
+ } catch (PerfSONARException e) {
- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ logger.error("[JUNIPERSTATUSADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve prompt");
- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ }
- // System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("[JuniperStatusAdapter] Prompt set in TelnetManager: "
+ prompt);
- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);
- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
- JuniperStatusAdapter adapter = new JuniperStatusAdapter();
- //adapter.connect(subject);
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();
- availableSpecificCommands = new ArrayList();
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; i++) {
- try {
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);
- url = properties.getProperty("service.r.mp." +
subject + ".url");
- port =
Integer.parseInt(properties.getProperty("service.r.mp."
- + subject + ".port"));
- prompt = properties.getProperty("service.r.mp." +
subject
- + ".prompt");
- caching =
Integer.parseInt(properties.getProperty("service.r.mp." + subject
- + ".cache"));
+ if (new ParameterChecker().checkParam(subject,
eventTypeString,
+ parameter)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }
- manager = new TelnetManager(url, port, false);
+ }
- } catch (NumberFormatException e1) {
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {
- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- } catch (PerfSONARException e1) {
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- logger.debug("[JuniperStatusAdapter] TelnetManager created: "
+ url
- + " " + port);
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {
- try {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- ((TelnetManager) manager).setPrompt(properties
- .getProperty("service.r.mp." +
subject + ".prompt"));
+ }
- } catch (PerfSONARException e) {
+ }
- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ if (temp.equalsIgnoreCase("")) {
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();
- logger.debug("[JuniperStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ }
- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }
- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ } else if (statusCommand.getMinParamCount() == 0) {
- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {
- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();
- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- // System.out.println("PARAMETERVALUE: " +
parameter);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {
- if (new
ParameterChecker().checkParam(subject, eventTypeString,
- parameter)) {
- statusCommand.addParameter(parameter);
- } else {
- temp = " Malicious
parameters detected.";
- valid = false;
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Malicious parameters
detected.");
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();
- }
+ } else if (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {
- if (statusCommand.getParameters().size() >=
statusCommand
- .getMinParamCount()
- &&
statusCommand.getParameters().size() <= statusCommand
- .getMaxParamCount()
&& valid) {
-
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand
= (StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT
RETURNED");
- temp =
cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();
- logger.info("CACHED RESULT
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ }
- }
- else if (valid) {
- valid = false;
- temp = " Wrong number of
parameters detected.";
- throw new PerfSONARException(
-
"error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
- }
+ }
- } else if (statusCommand.getMinParamCount() == 0) {
+ if (temp.equalsIgnoreCase("")) {
- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
-
- StatusCommandInterface cachedCommand =
(StatusCommandInterface)it.next();
-
- if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
-
- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
-
- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();
- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ }
- } else {
+ } else {
- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters
detected.");
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
- }
+ }
- logger.info("[JuniperStatusAdapter] Command executed
succesfully");
+ logger.info("[JuniperStatusAdapter] Command executed succesfully");
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }
- logger.info("[JuniperStatusAdapter] Constructing response
message");
+ logger.info("[JuniperStatusAdapter] Constructing response message");
- Message response = new Message();
+ Message response = new Message();
- Data[] respData = new Data[1];
- Metadata[] respMetaData;
- respData = request.getDataArray();
- respData[0].clearChildren();
- respData[0].setChild(datum);
- respMetaData = request.getMetadataArray();
- response.setMetadata(respMetaData[0]);
- response.setData(respData[0]);
+ Data[] respData = new Data[1];
+ Metadata[] respMetaData;
+ respData = request.getDataArray();
+ respData[0].clearChildren();
+ respData[0].setChild(datum);
+ respMetaData = request.getMetadataArray();
+ response.setMetadata(respMetaData[0]);
+ response.setData(respData[0]);
- // System.err.println(respMetaData);
- // System.err.println(respData);
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");
- // response.setSonarMetadata(request.getSonarMetadata());
- // response.setSonarData(new Data[] { data });
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });
- logger.info("[JuniperStatusAdapter] takeAction finished");
+ logger.info("[JuniperStatusAdapter] takeAction finished");
- return response;
- // return new ServiceEngineResponse();
+ return response;
+ // return new ServiceEngineResponse();
- }
+ }
- // ---------------------- Stand-alond Test Method
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {
- public static void main(String[] args) {
+ try {
+ JuniperStatusAdapter adapter = new JuniperStatusAdapter();
- try {
- JuniperStatusAdapter adapter = new
JuniperStatusAdapter();
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("juniper1");
- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniper1");
+ adapter.connect("juniper1");
- adapter.connect("juniper1");
+ StatusCommandInterface statusCommand;
- StatusCommandInterface statusCommand;
+ try {
- try {
+ statusCommand = adapter.getCommand("STATUS_CONNECTIONS");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
- statusCommand =
adapter.getCommand("STATUS_CONNECTIONS");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(adapter.filterResult(temp, statusCommand));
- System.out.println(adapter.filterResult(temp,
statusCommand));
+ } catch (PerfSONARException e) {
- } catch (PerfSONARException e) {
+ //e.printStackTrace();
- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -19,195 +19,189 @@
*
*/
public class StatusCommand implements StatusCommandInterface {
-
- // ---------------------- class-fields
-
- private String deviceName = null;
- private String description = null;
- private String command = null;
- private String result = null;
- private List parameters = null;
-
- private int minParamCount = 0;
- private int maxParamCount = 0;
- private long timestamp = 0;
-
- // ---------------------- constructors
-
- public StatusCommand(String description, String command) {
-
- this.description = description;
- this.command = command;
- parameters = new ArrayList();
-
- }
+ // ---------------------- class-fields
+ private String deviceName = null;
+ private String description = null;
+ private String command = null;
+ private String result = null;
+ private List parameters = null;
+ private int minParamCount = 0;
+ private int maxParamCount = 0;
+ private long timestamp = 0;
- // ---------------------- public methods
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getCommand()
- */
- public String getCommand() {
-
- return command;
-
- }
+ // ---------------------- constructors
+ public StatusCommand(String description, String command) {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getDescription()
- */
- public String getDescription() {
-
- return description;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getResult()
- */
- public String getResult() {
-
- return result;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getFilteredResult()
- */
- public String getFilteredResult() {
-
- return getResult();
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getFilteredResult()
- */
- public List getRecordsResult() {
-
- return null;
-
- }
+ this.description = description;
+ this.command = command;
+ parameters = new ArrayList();
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getParameters()
- */
- public List getParameters() {
-
- return parameters;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getParameterString()
- */
- public String getParameterString() {
-
- String parameterString = "";
- Iterator it = parameters.iterator();
-
- while (it.hasNext()) {
- parameterString += it.next();
- }
-
- parameterString.replace("\n", "");
-
- return parameterString;
-
- }
+ // ---------------------- public methods
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getCommand()
+ */
+ public String getCommand() {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setCommand(java.lang.String)
- */
- public void setCommand(String command) {
-
- this.command = command;
-
- }
+ return command;
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setDescription(java.lang.String)
- */
- public void setDescription(String description) {
-
- this.description = description;
-
- }
+ }
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setResult(java.lang.String)
- */
- public void setResult(String result) {
-
- this.result = result;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getDescription()
+ */
+ public String getDescription() {
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setParameters(java.util.List)
- */
- public void setParameters(List parameters) {
-
- this.parameters = parameters;
-
- }
-
- /* (non-Javadoc)
- * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#addParameter(java.lang.String)
- */
- public void addParameter(String parameter) {
-
- parameters.add(parameter);
-
- }
+ return description;
- public int getMinParamCount() {
+ }
- return minParamCount;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getResult()
+ */
+ public String getResult() {
- public int getMaxParamCount() {
+ return result;
- return maxParamCount;
-
- }
+ }
- public void setMinParamCount(int count) {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getFilteredResult()
+ */
+ public String getFilteredResult() {
- minParamCount = count;
-
- }
+ return getResult();
- public void setMaxParamCount(int count) {
+ }
- maxParamCount = count;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getFilteredResult()
+ */
+ public List getRecordsResult() {
- public long getTimestamp() {
+ return null;
- return timestamp;
-
- }
+ }
- public void setTimestamp(long time) {
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getParameters()
+ */
+ public List getParameters() {
- timestamp = time;
-
- }
+ return parameters;
- public String getDeviceName() {
+ }
- return deviceName;
-
- }
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#getParameterString()
+ */
+ public String getParameterString() {
- public void setDeviceName(String deviceName) {
+ String parameterString = "";
+ Iterator it = parameters.iterator();
- this.deviceName = deviceName;
-
- }
-
+ while (it.hasNext()) {
+ parameterString += it.next();
+ }
+
+ parameterString.replace("\n", "");
+
+ return parameterString;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setCommand(java.lang.String)
+ */
+ public void setCommand(String command) {
+
+ this.command = command;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setDescription(java.lang.String)
+ */
+ public void setDescription(String description) {
+
+ this.description = description;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setResult(java.lang.String)
+ */
+ public void setResult(String result) {
+
+ this.result = result;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#setParameters(java.util.List)
+ */
+ public void setParameters(List parameters) {
+
+ this.parameters = parameters;
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.perfsonar.service.measurementPoint.bgp.commands.lookingGlass.StatusCommandInterface#addParameter(java.lang.String)
+ */
+ public void addParameter(String parameter) {
+
+ parameters.add(parameter);
+
+ }
+
+ public int getMinParamCount() {
+
+ return minParamCount;
+
+ }
+
+ public int getMaxParamCount() {
+
+ return maxParamCount;
+
+ }
+
+ public void setMinParamCount(int count) {
+
+ minParamCount = count;
+
+ }
+
+ public void setMaxParamCount(int count) {
+
+ maxParamCount = count;
+
+ }
+
+ public long getTimestamp() {
+
+ return timestamp;
+
+ }
+
+ public void setTimestamp(long time) {
+
+ timestamp = time;
+
+ }
+
+ public String getDeviceName() {
+
+ return deviceName;
+
+ }
+
+ public void setDeviceName(String deviceName) {
+
+ this.deviceName = deviceName;
+
+ }
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -19,50 +19,49 @@
*/
public interface StatusCommandInterface extends CommandInterface {
- public abstract String getDeviceName();
-
- public abstract String getCommand();
+ public abstract String getDeviceName();
- public abstract String getDescription();
+ public abstract String getCommand();
- public abstract String getResult();
+ public abstract String getDescription();
- public abstract String getFilteredResult();
-
- public abstract List getRecordsResult();
+ public abstract String getResult();
- public abstract List getParameters();
-
- public abstract String getParameterString();
-
- public abstract int getMinParamCount();
-
- public abstract int getMaxParamCount();
-
- public abstract long getTimestamp();
+ public abstract String getFilteredResult();
- /**
- * Returns a enumeration of the paramteres, converted into a space
- * seperated string.
- *
- * @return String with space seperated String
- */
- public abstract void setDeviceName(String deviceName);
-
- public abstract void setCommand(String command);
+ public abstract List getRecordsResult();
- public abstract void setDescription(String description);
+ public abstract List getParameters();
- public abstract void setResult(String result);
+ public abstract String getParameterString();
- public abstract void setParameters(List parameters);
+ public abstract int getMinParamCount();
- public abstract void addParameter(String parameter);
-
- public abstract void setMinParamCount(int count);
-
- public abstract void setMaxParamCount(int count);
-
- public abstract void setTimestamp(long time);
+ public abstract int getMaxParamCount();
-}
\ No newline at end of file
+ public abstract long getTimestamp();
+
+ /**
+ * Returns a enumeration of the paramteres, converted into a space
+ * seperated string.
+ *
+ * @return String with space seperated String
+ */
+ public abstract void setDeviceName(String deviceName);
+
+ public abstract void setCommand(String command);
+
+ public abstract void setDescription(String description);
+
+ public abstract void setResult(String result);
+
+ public abstract void setParameters(List parameters);
+
+ public abstract void addParameter(String parameter);
+
+ public abstract void setMinParamCount(int count);
+
+ public abstract void setMaxParamCount(int count);
+
+ public abstract void setTimestamp(long time);
+}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -17,17 +17,16 @@
*
*/
public interface RemoteManager {
-
- public void connect() throws PerfSONARException ;
-
- public void connect(String userName, String loginPrompt, String
passwd, String passwdPrompt) throws PerfSONARException ;
-
- public void connect(String userName, String passwd) throws
PerfSONARException ;
-
- public String executeCommand(String command) ;
-
- public void disconnect();
-
- public void connect(String userName, String keyUrl, String
passphrase) throws PerfSONARException;
+ public void connect() throws PerfSONARException;
+
+ public void connect(String userName, String loginPrompt, String passwd,
String passwdPrompt) throws PerfSONARException;
+
+ public void connect(String userName, String passwd) throws
PerfSONARException;
+
+ public String executeCommand(String command);
+
+ public void disconnect();
+
+ public void connect(String userName, String keyUrl, String passphrase)
throws PerfSONARException;
}
Added:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/MyUserInfo.java
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,18 +1,24 @@
/*
- * Created on Mar 27, 2005
- * Version Number: 0.1
+ * Created on Jan 08, 2008
+ * Version Number: 1.0
* Project: perfSonar
*/
package org.perfsonar.service.measurementPoint.remote.ssh;
import java.io.IOException;
import java.io.InputStream;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Provider.Service;
+import java.util.Iterator;
+import java.util.Set;
+import javax.swing.SwingUtilities;
+
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
-import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import com.jcraft.jsch.Channel;
@@ -29,262 +35,312 @@
*/
public class SshKeyManager implements RemoteManager {
- // ------------------------------------- class - fields
+ // ------------------------------------- class - fields
+ private JSch jsch = null;
+ private Session session = null;
+ private UserInfo ui = null;
+ private String url = null;
+ private String userName = null;
+ private String keyUrl = null;
+ private String passphrase = null;
+ private LoggerComponent logger = null;
+ private boolean connected = false;
+ private int timeout = 0;
- private JSch jsch = null;
+ public SshKeyManager(String url, String userName, String keyUrl,
+ boolean connect, int timeout) {
- private Session session = null;
+ super();
+ this.url = url;
+ this.userName = userName;
+ this.keyUrl = keyUrl;
+ ui = new MyUserInfo(keyUrl);
+ this.timeout = timeout;
- private UserInfo ui = new MyUserInfo();
+ try {
- private String url = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String userName = null;
+ } catch (PerfSONARException e1) {
- private String keyUrl = null;
+ logger.error("[SSHKEYMANAGER][Constructor]" +
e1.getStackTrace().toString());
- private LoggerComponent logger = null;
+ }
- private boolean connected = false;
+ if (connect) {
- public SshKeyManager(String url, String userName, String keyUrl,
- boolean connect) {
+ try {
- super();
- this.url = url;
- this.userName = userName;
- this.keyUrl = keyUrl;
+ connect(userName, keyUrl);
- try {
+ } catch (PerfSONARException e) {
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ logger.error("[SshKeyManager] AuthenticationException during
connection");
- } catch (PerfSONARException e1) {
+ }
- e1.printStackTrace();
+ } // connect
- }
+ } // SshKeyManager
+
+ public SshKeyManager(String url, String userName, String keyUrl,
+ String passphrase, boolean connect, int timeout) {
- if (connect) {
+ super();
+ this.url = url;
+ this.userName = userName;
+ this.keyUrl = keyUrl;
+ this.passphrase = passphrase;
+ ui = new MyUserInfo(keyUrl);
+ this.timeout = timeout;
- try {
+ try {
- connect(userName, keyUrl);
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e1) {
- logger
- .error("[SshKeyManager]
AuthenticationException during connection");
+ logger.error("[SSHKEYMANAGER][Constructor]" +
e1.getStackTrace().toString());
- }
+ }
- } // connect
+ if (connect) {
- } // SshKeyManager
+ try {
- public void connect() throws PerfSONARException {
+ connect(userName, keyUrl);
- logger.debug("[SshKeyManager] connecting initiatec ...");
+ } catch (PerfSONARException e) {
- try {
+ logger.error("[SshKeyManager] AuthenticationException during
connection");
- //Create a new Client for communication
- jsch = new JSch();
+ }
- //Set key identity file
- jsch.addIdentity(keyUrl);
+ } // connect
- //Create session
- session = jsch.getSession(userName, url, 22);
+ } // SshKeyManager
- //Set user info
- session.setUserInfo(ui);
+ public void connect() throws PerfSONARException {
- //Connect
- session.connect();
+ logger.debug("[SshKeyManager] connecting initiatec ...");
- connected = true;
+ try {
- logger.debug("[SshKeyManager] Connection
established");
+ //Create a new Client for communication
+ jsch = new JSch();
+
+ //Set key identity file
+ if (passphrase == null)
+ jsch.addIdentity(keyUrl);
+ else jsch.addIdentity(keyUrl, passphrase);
- } catch (JSchException e) {
+ //Create session
+ session = jsch.getSession(userName, url, 22);
- e.printStackTrace();
- throw new PerfSONARException(
- "[SshKeyManager] An error occured");
+ //Set user info
+ session.setUserInfo(ui);
- }
+ //Connect
+ session.connect();
- } //connect
+ connected = true;
- public void connect(String userName, String loginPrompt, String
passwd,
- String passwdPrompt) throws PerfSONARException {
+ logger.debug("[SshKeyManager] Connection established");
- connect(userName, passwd);
+ } catch (JSchException e) {
- } //connect
+ logger.error("[SSHKEYMANAGER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "[SshKeyManager] An error occured");
- public void connect(String username, String keyUrl)
- throws PerfSONARException {
+ }
- logger.debug("[SshKeyManager] connecting initiated ...");
+ } //connect
- try {
+ public void connect(String userName, String loginPrompt, String passwd,
+ String passwdPrompt) throws PerfSONARException {
- //Create a new Client for communication
- jsch = new JSch();
+ connect(userName, passwd);
- //Set key identity file
- jsch.addIdentity(keyUrl);
+ } //connect
- //Create session
- session = jsch.getSession(userName, url, 22);
+ public void connect(String username, String keyUrl)
+ throws PerfSONARException {
- //Set user info
- session.setUserInfo(ui);
+ logger.debug("[SshKeyManager] connecting initiated ...");
- //Connect
- session.connect();
+ try {
- connected = true;
+ //Create a new Client for communication
+ jsch = new JSch();
- logger.debug("[SshKeyManager] Connection
established");
+ //Set key identity file
+ jsch.addIdentity(keyUrl);
- } catch (JSchException e) {
+ //Create session
+ session = jsch.getSession(userName, url, 22);
- e.printStackTrace();
- throw new PerfSONARException(
- "[SshKeyManager] An error occured");
+ //Set user info
+ session.setUserInfo(ui);
- }
+ //Connect
+ session.connect();
- } //connect
+ connected = true;
- public void connect(String username, String keyUrl, String
- passphrase) throws PerfSONARException {
+ logger.debug("[SshKeyManager] Connection established");
- logger.debug("[SshKeyManager] connecting initiated ...");
+ } catch (JSchException e) {
- try {
+ logger.error("[SSHKEYMANAGER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "[SshKeyManager] An error occured");
- //Create a new Client for communication
- jsch = new JSch();
+ }
- //Set key identity file
- jsch.addIdentity(keyUrl, passphrase);
+ } //connect
- //Create session
- session = jsch.getSession(userName, url, 22);
+ public void connect(String username, String keyUrl, String passphrase)
throws PerfSONARException {
- //Set user info
- session.setUserInfo(ui);
+ logger.debug("[SshKeyManager] connecting initiated ...");
- //Connect
- session.connect();
+ try {
- connected = true;
+ //Create a new Client for communication
+ jsch = new JSch();
- logger.debug("[SshKeyManager] Connection
established");
+ //Set key identity file
+ jsch.addIdentity(keyUrl, passphrase);
- } catch (JSchException e) {
+ //Create session
+ session = jsch.getSession(userName, url, 22);
- e.printStackTrace();
- throw new PerfSONARException(
- "[SshKeyManager] An error occured");
+ //Set user info
+ session.setUserInfo(ui);
- }
+ //Connect
+ session.connect();
- } //connect
+ connected = true;
- public Channel getSshSessionChannel() {
+ logger.debug("[SshKeyManager] Connection established");
- try {
+ } catch (JSchException e) {
- return session.openChannel("exec");
+ logger.error("[SSHKEYMANAGER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "[SshKeyManager] An error occured");
- } catch (JSchException e) {
+ }
- e.printStackTrace();
- return null;
- }
+ } //connect
- }// getSshSessionChannel
+ public Channel getSshSessionChannel() {
- public String executeCommand(String command) {
+ try {
- try {
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
- channel.setInputStream(null);
- ((ChannelExec) channel).setErrStream(System.err);
+ return session.openChannel("exec");
- InputStream in = channel.getInputStream();
+ } catch (JSchException e) {
- channel.connect();
+ logger.error("[SSHKEYMANAGER][GetSshChannel]" +
e.getStackTrace().toString());
+ return null;
+ }
- String result = "";
- byte[] tmp = new byte[1024];
- while (true) {
- while (in.available() > 0) {
- int i = in.read(tmp, 0, 1024);
- if (i < 0)
- break;
- result += new String(tmp, 0, i);
- System.out.print(new String(tmp, 0,
i));
- }
- if (channel.isClosed()) {
- System.out.println("exit-status: " +
channel.getExitStatus());
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (Exception ee) {
- }
- }
- channel.disconnect();
- session.disconnect();
- return result;
- } catch (JSchException e) {
- e.printStackTrace();
- return "An error occured";
- } catch (IOException e) {
- e.printStackTrace();
- return "An error occured";
- }
+ }// getSshSessionChannel
+
+ /**
+ * Executes the command in the remote machine over the Ssh connection
+ *
+ * @param cmd
+ * command
+ */
+ public String executeCommand(String cmd) {
- } //executeCommand
+ String result = "";
+
+ try {
+ if (jsch == null) {
+ ui = new MyUserInfo(this.keyUrl);
+ jsch = new JSch();
+ jsch.addIdentity(keyUrl);
+ session = jsch.getSession(this.userName, this.url,
22);
+ session.setUserInfo(ui);
+ }
+
+ if (!session.isConnected()) {
+ session.connect();
+ }
- public void disconnect() {
+ Channel channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(cmd);
+ channel.setInputStream(null);
+ ((ChannelExec) channel).setErrStream(System.err);
- session.disconnect();
+ InputStream in = channel.getInputStream();
- } // disconnect
+ channel.connect();
+ if (timeout != 0){
+ final Channel channel2 = channel;
- public static class MyUserInfo implements UserInfo {
- public String getPassword() {
- return null;
- }
+ Runnable updateAComponent = new Runnable() {
+
+ public void run() {
+ try {
+
logger.debug("[SshKeyManager][ExecuteCommand]Sleeping for " + timeout + "
milliseconds...");
+ Thread.sleep(timeout);
+
logger.debug("[SshKeyManager][ExecuteCommand]Sleeping ended");
+ channel2.disconnect();
+ session.disconnect();
+ } catch (InterruptedException ex) {
+
+
logger.error("[SshKeyManager][ExecuteCommand]" +
ex.getStackTrace()[0].toString());
+
+ }
+ }
+ };
+ SwingUtilities.invokeLater(updateAComponent);
+ }
+ byte[] tmp = new byte[1024];
+ while (true) {
+ while (in.available() > 0) {
+ int i = in.read(tmp, 0, 1024);
+ if (i < 0) {
+ break;
+ }
+ result += new String(tmp, 0, i);
+ System.out.println(new String(tmp, 0, i));
+ }
+ if (channel.isClosed()) {
+ System.out.println("exit-status: " +
channel.getExitStatus());
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (Exception ee) {
+ ee.printStackTrace();
+ }
+ }
+ if (timeout == 0){
+ channel.disconnect();
+ session.disconnect();
+ }
+ logger.debug("result: " + result);
+ return result;
+ } catch (JSchException e) {
+ e.printStackTrace();
+ return "An Error Occured";
+ } catch (IOException e) {
+ e.printStackTrace();
+ return "An Error Occured";
+ }
- public boolean promptYesNo(String str) {
- return true;
- }
+ }// executeCommand
- public String getPassphrase() {
- return null;
- }
+ public void disconnect() {
- public boolean promptPassphrase(String message) {
- return true;
- }
+ session.disconnect();
- public boolean promptPassword(String message) {
- return true;
- }
+ } // disconnect
- public void showMessage(String message) {
- System.err.println(message);
- }
- }
-
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,18 +1,25 @@
/*
- * Created on Jun 20th, 2005
- * Version Number: 0.2
- * Project: perfSonar
+ * Created on Jan 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSONAR
*/
package org.perfsonar.service.measurementPoint.remote.ssh;
import java.io.IOException;
import java.io.InputStream;
+import java.security.Provider;
+import java.security.Security;
+import java.security.Provider.Service;
+import java.util.Iterator;
+import java.util.Set;
+import javax.crypto.Cipher;
+import javax.swing.SwingUtilities;
+
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
-import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import com.jcraft.jsch.Channel;
@@ -33,261 +40,250 @@
*/
public class SshManager implements RemoteManager {
- // ---------------------- class fields
+ // ---------------------- class fields
+ private JSch jsch = null;
+ private Session session = null;
+ private UserInfo ui = null;
+ private String url = null;
+ private String userName = null;
+ private String password = null;
+ private LoggerComponent logger = null;
+ private boolean connected = false;
+ private int timeout = 0;
- private JSch jsch = null;
+ // ---------------------- constructors
+ public SshManager(String url, String userName, String password,
+ boolean connect, int timeout) {
- private Session session = null;
+ super();
+ this.url = url;
+ this.userName = userName;
+ this.password = password;
+ this.timeout = timeout;
+
+ //ui = new MyUserInfo(password);
+
- private UserInfo ui = null;
+ try {
- private String url = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- private String userName = null;
+ } catch (PerfSONARException e1) {
- private String password = null;
+ logger.error("[SSHMANAGER][Constructor]" +
e1.getStackTrace().toString());
- private LoggerComponent logger = null;
+ }
- private boolean connected = false;
+ if (connect) {
- // ---------------------- constructors
+ try {
- public SshManager(String url, String userName, String password,
- boolean connect) {
+ connect();
- super();
- this.url = url;
- this.userName = userName;
- this.password = password;
- ui = new MyUserInfo(password);
+ } catch (PerfSONARException e) {
- try {
+ logger.error("[SshManager] AuthenticationException during
connection");
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ }
- } catch (PerfSONARException e1) {
+ } // connect
- e1.printStackTrace();
+ } // SshManager
- }
+ // ---------------------- public methods
+ /**
+ * Conects to the remote host
+ *
+ */
+ public void connect() throws PerfSONARException {
- if (connect) {
+ try {
- try {
+ logger.debug("[SshManager] connecting initiated ...");
+ //System.out.println("[SshManager] connecting initiated ...");
- connect();
+ // Create a new Client for communication
+ jsch = new JSch();
- } catch (PerfSONARException e) {
+ // Create session
+ session = jsch.getSession(userName, url, 22);
- logger
- .error("[SshManager] AuthenticationException
during connection");
+ //Set user info
+ session.setUserInfo(ui);
- }
+ //Connect
+ session.connect();
- } // connect
+ connected = true;
- } // SshManager
+ } catch (JSchException e) {
- // ---------------------- public methods
+ logger.error("[SSHMANAGER][Connect]" +
e.getStackTrace().toString());
- /**
- * Conects to the remote host
- *
- */
- public void connect() throws PerfSONARException {
+ }
+ }// connect
+
+ /**
+ * Conects to the remote host
+ *
+ */
+ public void connect(String userName, String loginPrompt, String password,
+ String passwordPrompt) throws PerfSONARException {
- try {
+ try {
- logger.debug("[SshManager] connecting initiated ...");
- System.out.println("[SshManager] connecting initiated
...");
+ logger.debug("[SshManager] connecting initiated ...");
+ //System.out.println("[SshManager] connecting initiated ...");
- // Create a new Client for communication
- jsch = new JSch();
+ // Create a new Client for communication
+ jsch = new JSch();
- // Create session
- session = jsch.getSession(userName, url, 22);
+ // Create session
+ session = jsch.getSession(userName, url, 22);
- //Set user info
- session.setUserInfo(ui);
+ //Set user info
+ session.setUserInfo(ui);
- //Connect
- session.connect();
+ //Connect
+ session.connect();
- connected = true;
+ connected = true;
- } catch (JSchException e) {
+ } catch (JSchException e) {
- logger.error(e.getStackTrace().toString());
+ logger.error("[SSHMANAGER][Connect]" +
e.getStackTrace().toString());
- }
- }// connect
+ }
+ }// connect
+ public void connect(String username, String keyUrl, String passphrase)
throws PerfSONARException {
- /**
- * Conects to the remote host
- *
- */
- public void connect(String userName, String loginPrompt, String
password,
- String passwordPrompt) throws PerfSONARException {
+ connect(username, keyUrl);
- try {
+ }// connect
+
+ /**
+ * Returns the SshChannelClient belonging to this Ssh connection
+ *
+ * @return SessionChannelClient
+ */
+ public Channel getSshChannel() throws PerfSONARException {
- logger.debug("[SshManager] connecting initiated ...");
- System.out.println("[SshManager] connecting initiated
...");
+ try {
- // Create a new Client for communication
- jsch = new JSch();
+ return session.openChannel("exec");
- // Create session
- session = jsch.getSession(userName, url, 22);
+ } catch (JSchException e) {
- //Set user info
- session.setUserInfo(ui);
+ logger.error("[SSHMANAGER][GetSshChannel]" +
e.getStackTrace().toString());
+ return null;
+ }
- //Connect
- session.connect();
+ }// getSshChannel
+
+ /**
+ * Executes the command in the remote machine over the Ssh connection
+ *
+ * @param cmd
+ * command
+ */
+ public String executeCommand(String cmd) {
- connected = true;
+ String result = "";
- } catch (JSchException e) {
+ try {
+
+ if (jsch == null) {
+ ui = new MyUserInfo(this.password);
+ jsch = new JSch();
+ session = jsch.getSession(this.userName, this.url,
22);
+ session.setUserInfo(ui);
+ }
+
+ if (!session.isConnected()) {
+ session.connect();
+
+ }
+
+ Channel channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(cmd);
+ channel.setInputStream(null);
+ ((ChannelExec) channel).setErrStream(System.err);
- logger.error(e.getStackTrace().toString());
+ InputStream in = channel.getInputStream();
- }
- }// connect
+ channel.connect();
+ if (timeout != 0){
+ final Channel channel2 = channel;
- public void connect(String username, String keyUrl, String
- passphrase) throws PerfSONARException {
+ Runnable updateAComponent = new Runnable() {
+
+ public void run() {
+ try {
+
logger.debug("[SshManager][ExecuteCommand]Sleeping for " + timeout + "
milliseconds...");
+ Thread.sleep(timeout);
+
logger.debug("[SshManager][ExecuteCommand]Sleeping ended");
+ channel2.disconnect();
+ session.disconnect();
+ } catch (InterruptedException ex) {
+ logger.error("[SshManager][ExecuteCommand]" +
ex.getStackTrace()[0].toString());
+ }
+ }
+ };
+ SwingUtilities.invokeLater(updateAComponent);
+ }
+ byte[] tmp = new byte[1024];
+ while (true) {
+ while (in.available() > 0) {
+ int i = in.read(tmp, 0, 1024);
+ if (i < 0) {
+ break;
+ }
+ result += new String(tmp, 0, i);
+ //System.out.println(new String(tmp, 0, i));
+ }
+ if (channel.isClosed()) {
+ //System.out.println("exit-status: " +
channel.getExitStatus());
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (Exception ee) {
+ ee.printStackTrace();
+ }
+ }
+ if (timeout == 0){
+ channel.disconnect();
+ session.disconnect();
+ }
+ //logger.debug("result: " + result);
+ return result;
+ } catch (JSchException e) {
+ e.printStackTrace();
+ return "An Error Occured";
+ } catch (IOException e) {
+ e.printStackTrace();
+ return "An Error Occured";
+ } catch (Exception t){
+ t.printStackTrace();
+ return "An Error Occured";
+ }
- connect (username, keyUrl);
+ }// executeCommand
+
+ /**
+ * Closing and disconnection management
+ *
+ */
+ public void disconnect() {
- }// connect
+ session.disconnect();
- /**
- * Returns the SshChannelClient belonging to this Ssh connection
- *
- * @return SessionChannelClient
- */
- public Channel getSshChannel() throws PerfSONARException {
+ }// disconnect
+ public void connect(String userName, String passwd)
+ throws PerfSONARException {
- try {
+ connect(userName, "Username:", passwd, "Password:");
- return session.openChannel("exec");
+ }
- } catch (JSchException e) {
-
- e.printStackTrace();
- return null;
- }
-
- }// getSshChannel
-
- /**
- * Executes the command in the remote machine over the Ssh connection
- *
- * @param cmd
- * command
- */
- public String executeCommand(String cmd) {
-
- String result = "";
-
- try {
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(cmd);
- channel.setInputStream(null);
- ((ChannelExec) channel).setErrStream(System.err);
-
- InputStream in = channel.getInputStream();
-
- channel.connect();
-
- byte[] tmp = new byte[1024];
- while (true) {
- while (in.available() > 0) {
- int i = in.read(tmp, 0, 1024);
- if (i < 0)
- break;
- result += new String(tmp, 0, i);
- System.out.print(new String(tmp, 0,
i));
- }
- if (channel.isClosed()) {
- System.out.println("exit-status: " +
channel.getExitStatus());
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (Exception ee) {
- }
- }
- channel.disconnect();
- session.disconnect();
- System.out.println("result: " + result);
- return result;
- } catch (JSchException e) {
- e.printStackTrace();
- return "An Error Occured";
- } catch (IOException e) {
- e.printStackTrace();
- return "An Error Occured";
- }
-
- }// executeCommand
-
-
- /**
- * Closing and disconnection management
- *
- */
- public void disconnect() {
-
- session.disconnect();
-
- }// disconnect
-
- public void connect(String userName, String passwd)
- throws PerfSONARException {
-
- connect(userName, "Username:", passwd, "Password:");
-
- }
-
- public static class MyUserInfo implements UserInfo {
-
- String passwd;
-
- public MyUserInfo(String passwd) {
-
- super();
- this.passwd = passwd;
-
- }
-
- public String getPassword() {
- return passwd;
- }
-
- public boolean promptYesNo(String str) {
- return true;
- }
-
- public String getPassphrase() {
- return null;
- }
-
- public boolean promptPassphrase(String message) {
- return true;
- }
-
- public boolean promptPassword(String message) {
- return true;
- }
-
- public void showMessage(String message) {
- System.err.println(message);
- }
- }
-
-
}
Modified:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
===================================================================
---
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
2008-02-06 15:18:55 UTC (rev 3319)
+++
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
2008-02-06 15:41:34 UTC (rev 3320)
@@ -1,17 +1,18 @@
/*
- * Created on Nov 24, 2005
- * Version Number: 0.1
+ * Created on Jan 8, 2009
+ * Version Number: 1.0
* Project: perfSonar
*/
package org.perfsonar.service.measurementPoint.remote.telnet;
import java.io.IOException;
+import javax.swing.SwingUtilities;
+
import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
import org.perfsonar.base.auxiliary.ComponentNames;
import org.perfsonar.base.auxiliary.components.logger.LoggerComponent;
import org.perfsonar.base.exceptions.PerfSONARException;
-import
org.perfsonar.service.measurementPoint.lookingGlassType.encryption.PasswordEncryptor;
import org.perfsonar.service.measurementPoint.remote.common.RemoteManager;
import de.mud.telnet.TelnetWrapper;
@@ -27,211 +28,225 @@
*/
public class TelnetManager implements RemoteManager {
- // ---------------------- class fields
+ // ---------------------- class fields
+ private TelnetWrapper telnet = null;
+ private String url = null;
+ private int port = -1;
+ private String prompt = null;
+ private LoggerComponent logger = null;
+ private boolean connected = false;
+ private int timeout = 0;
- private TelnetWrapper telnet = null;
+ // ---------------------- constructors
+ public TelnetManager(String url, int port, boolean connect, int timeout)
{
- private String url = null;
- private int port = -1;
- private String prompt = null;
-
- private LoggerComponent logger = null;
-
- private boolean connected = false;
+ super();
+ this.url = url;
+ this.port = port;
+ this.timeout = timeout;
- // ---------------------- constructors
+ try {
- public TelnetManager(String url, int port, boolean connect) {
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);
- super();
- this.url = url;
- this.port = port;
-
+ } catch (PerfSONARException e1) {
+
+ logger.error("[TELNETMANAGER][Constructor]" +
e1.getStackTrace().toString());
+
+ }
+
+ if (connect) {
+
+ logger.debug("[TelnetManager] Trying to connect ...");
+ // Create a new Client for communication
+ telnet = new TelnetWrapper();
+
+ // Connect to the remote host
+ try {
+
+ telnet.connect(url, port);
+ telnet.setPrompt("chaos4>");
+ connected = true;
+
+ } catch (IOException e) {
+
+ logger.error("[TelnetManager] Connection failed");
+ logger.error("[TelnetManager] " +
e.getStackTrace().toString());
+
+ }
+
+ logger.debug("[TelnetManager] Connection established");
+
+ }//connect
+
+ }
+
+ // ---------------------- public methods
+ public void connect() {
+
+ logger.debug("[TelnetManager] Trying to connect ... ");
+
+ // Create a new Client for communication
+ telnet = new TelnetWrapper();
+
+ // Connect to the remote host
try {
-
- logger = (LoggerComponent)AuxiliaryComponentManager.
-
getInstance().getComponent(ComponentNames.LOGGER);
-
- } catch (PerfSONARException e1) {
-
- e1.printStackTrace();
-
- }
-
- if (connect) {
- logger.debug("[TelnetManager] Trying to connect
...");
- // Create a new Client for communication
- telnet = new TelnetWrapper();
+ logger.debug("Connecting on port: " + port + " url: " + url);
+ telnet.connect(url, port);
- // Connect to the remote host
- try {
-
- telnet.connect(url, port);
- telnet.setPrompt("chaos4>");
- connected = true;
-
- } catch (IOException e) {
-
- logger.error("[TelnetManager] Connection
failed");
- logger.error("[TelnetManager] " +
e.getStackTrace().toString());
-
- }
-
- logger.debug("[TelnetManager] Connection
established");
-
- }//connect
+ } catch (IOException e) {
- }
+ logger.error("[TelnetManager] Connection failed");
+ logger.error("[TelnetManager] " + e.getStackTrace().toString());
- // ---------------------- public methods
+ }
- public void connect() {
-
- logger.debug("[TelnetManager] Trying to connect ... ");
+ telnet.setPrompt(prompt);
+ connected = true;
- // Create a new Client for communication
- telnet = new TelnetWrapper();
+ logger.debug("[TelnetManager] Connection established");
- // Connect to the remote host
- try {
-
- //System.out.println("Connecting on port: " + port +
" url: " + url);
- telnet.connect(url, port);
-
- } catch (IOException e) {
-
- logger.error("[TelnetManager] Connection failed");
- logger.error("[TelnetManager] " +
e.getStackTrace().toString());
-
- }
-
- telnet.setPrompt(prompt);
- connected = true;
-
- logger.debug("[TelnetManager] Connection established");
+ }//connect
+ public void connect(String userName, String loginPrompt, String passwd,
String passwdPrompt) {
- }//connect
-
- public void connect(String userName, String loginPrompt, String
passwd, String passwdPrompt) {
-
- logger.debug("[TelnetManager] Trying to connect ... ");
+ logger.debug("[TelnetManager] Trying to connect ... ");
- // Create a new Client for communication
- telnet = new TelnetWrapper();
+ // Create a new Client for communication
+ telnet = new TelnetWrapper();
- // Connect to the remote host
- try {
-
- //System.out.println("Connecting on port: " + port +
" url: " + url);
-
//System.out.println("---------------------------------------------");
- telnet.connect(url, port);
- //System.out.println("Logging in ...");
- telnet.login(userName, loginPrompt, passwd,
passwdPrompt);
- //System.out.println("logged in !!");
-
- } catch (IOException e) {
-
- logger.error("[TelnetManager] Connection failed");
- logger.error("[TelnetManager] " +
e.getStackTrace().toString());
-
- }
-
- telnet.setPrompt(prompt);
- //System.out.println("prompt: " + prompt);
- connected = true;
-
- logger.debug("[TelnetManager] Connection established");
+ // Connect to the remote host
+ try {
- }//connect
+ logger.debug("Connecting on port: " + port + " url: " + url);
+ logger.debug("---------------------------------------------");
+ telnet.connect(url, port);
+ logger.debug("Logging in ...");
+ telnet.login(userName, loginPrompt, passwd, passwdPrompt);
+ logger.debug("logged in !!");
- public void connect(String username, String keyUrl, String passphrase)
- throws PerfSONARException {
+ } catch (IOException e) {
- connect (username, keyUrl);
+ logger.error("[TelnetManager] Connection failed");
+ logger.error("[TelnetManager] " + e.getStackTrace().toString());
- }//connect
+ }
+
+ telnet.setPrompt(prompt);
+ logger.debug("prompt: " + prompt);
+ connected = true;
+
+ logger.debug("[TelnetManager] Connection established");
+
+ }//connect
+ public void connect(String username, String keyUrl, String passphrase)
+ throws PerfSONARException {
+
+ connect(username, keyUrl);
+
+ }//connect
+ /**
+ * This method sets the prompt. This prompt is used to collect all output
+ * from the remote operation, ie all output is collected until this
prompt
+ * is encountered.
+ *
+ * @param prompt
+ */
+ public void setPrompt(String prompt) {
+
+ this.prompt = prompt;
+
+ if (telnet != null) {
+ telnet.setPrompt(prompt);
+ }
+
+ }
+
+ /**
+ * This method executes a command on the remote machine and returns a
string
+ * containing the captures output from standardout of that remote
process.
+ * All output is contained in this string until the earlier configured
+ * prompt is encountered.
+ *
+ * @param command
+ * @return String Output from the process
+ */
+ public String executeCommand(String command) {
+
+ System.out.println("[TelnetManager] Executing command");
+
+ if (connected) {
+
+ try {
+
+ String temp;
+
+ if (timeout != 0){
+ final TelnetWrapper telnet2 = telnet;
- /**
- * This method sets the prompt. This prompt is used to collect all
output
- * from the remote operation, ie all output is collected until this
prompt
- * is encountered.
- *
- * @param prompt
- */
- public void setPrompt(String prompt) {
-
- this.prompt = prompt;
-
- if (telnet != null)
-
- telnet.setPrompt(prompt);
-
- }
+ Runnable updateAComponent = new Runnable() {
+
+ public void run() {
+ try {
+
logger.debug("[TelnetManager][ExecuteCommand]Sleeping for " + timeout + "
milliseconds...");
+ Thread.sleep(timeout);
+
logger.debug("[TelnetManager][ExecuteCommand]Sleeping ended");
- /**
- * This method executes a command on th remote machine and returns a
string
- * containing the captures output from standardout of that remote
process.
- * All output is contained in this string until the earlier configured
- * prompt is encountered.
- *
- * @param command
- * @return String Output from the process
- */
- public String executeCommand(String command) {
-
- logger.debug("[TelnetManager] Executing command");
-
- if (connected) {
-
- try {
-
- String temp;
- temp = telnet.send(command);
+ telnet2.disconnect();
+ } catch (IOException ex) {
+
+
logger.error("[TelnetManager][ExecuteCommand]" +
ex.getStackTrace()[0].toString());
+ } catch (InterruptedException ex) {
+ }
+ }
+ };
+ SwingUtilities.invokeLater(updateAComponent);
+ }
+ temp = telnet.send(command);
+ //logger.debug("[TelnetManager][ExecuteCommand] result: " +
temp);
+ if(timeout==0)
+ telnet.disconnect();
+ if (temp == null)
+ temp = "";
+ return temp;
-
- //telnet.disconnect();
- return temp;
-
- } catch (IOException e) {
-
- logger.error("[TelnetManager] Execution of
command failed");
- logger.error("[TelnetManager] " +
e.getStackTrace().toString());
- e.printStackTrace();
-
- }
- }//connected
-
- return null;
-
- }//executeCommand
+ } catch (IOException e) {
- /**
- * Closing and disconnection management
- *
- */
- public void disconnect() {
+ e.printStackTrace();
+ logger.debug("[TelnetManager][ExecuteCommand]TimeOut!");
+ return "";
- if (connected) {
-
- try {
-
- telnet.disconnect();
- connected = false;
-
- } catch (IOException e) {
-
- logger.error("[TelnetManager] Disconnection
failed");
- logger.error("[TelnetManager] " +
e.getStackTrace().toString());
-
- }
- }//connected
+ }
+ }//connected
- }//disconnect
+ return null;
- public void connect(String userName, String passwd) throws
PerfSONARException {
+ }//executeCommand
+ /**
+ * Closing and disconnection management
+ *
+ */
+ public void disconnect() {
- connect(userName, "Username:", passwd, "Password:");
-
- }
+ if (connected) {
+
+ try {
+
+ telnet.disconnect();
+ connected = false;
+
+ } catch (IOException e) {
+
+ logger.error("[TelnetManager] Disconnection failed");
+ logger.error("[TelnetManager] " +
e.getStackTrace().toString());
+
+ }
+ }//connected
+
+ }//disconnect
+ public void connect(String userName, String passwd) throws
PerfSONARException {
+
+ connect(userName, "Username:", passwd, "Password:");
+
+ }
}
Added:
branches/geant2_java-sshtelnet-mp-STABLE/src/main/java/org/perfsonar/service/measurementPoint/webAdmin/SSHTelnetHandler.java
- perfsonar: r3320 - in branches/geant2_java-sshtelnet-mp-STABLE: ant conf conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters doc doc/commands doc/schema samples src/main/java/org/perfsonar/service/measurementPoint src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters src/main/java/org/perfso nar/service/measurementPoint/lookingGlassType/ip/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6 src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands src/main/java/org/perfsonar/service/measurementPoint/remote/common src/main/java/org/perfsonar/service/measurementPoint/remote/ssh src/main/java/org/perfsonar/service/measurementPoint/remote/telnet src/main/java/org/perfsonar/service/measurementPoint/webAdmin, svnlog, 02/06/2008
Archive powered by MHonArc 2.6.16.