Skip to Content.
Sympa Menu

perfsonar-dev - perfsonar: r3194 - in trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint: lookingGlassType/bgp lookingGlassType/bgp/adapters lookingGlassType/bgp/commands lookingGlassType/encryption lookingGlassType/engine/adapters lookingGlassType/engine/commands lookingGlassType/ip lookingGlassType/ip/adapters lookingGlassType/ip/commands lookingGlassType/ipv6 lookingGlassType/ipv6/adapters lookingGlassType/ipv6/commands lookingGlassType/metadata lookingGlassType/status lookingGlassType/status/adapters lookingGlassType/status/commands remote/common remote/ssh remote/telnet

Subject: perfsonar development work

List archive

perfsonar: r3194 - in trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint: lookingGlassType/bgp lookingGlassType/bgp/adapters lookingGlassType/bgp/commands lookingGlassType/encryption lookingGlassType/engine/adapters lookingGlassType/engine/commands lookingGlassType/ip lookingGlassType/ip/adapters lookingGlassType/ip/commands lookingGlassType/ipv6 lookingGlassType/ipv6/adapters lookingGlassType/ipv6/commands lookingGlassType/metadata lookingGlassType/status lookingGlassType/status/adapters lookingGlassType/status/commands remote/common remote/ssh remote/telnet


Chronological Thread 
  • From:
  • To:
  • Subject: perfsonar: r3194 - in trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint: lookingGlassType/bgp lookingGlassType/bgp/adapters lookingGlassType/bgp/commands lookingGlassType/encryption lookingGlassType/engine/adapters lookingGlassType/engine/commands lookingGlassType/ip lookingGlassType/ip/adapters lookingGlassType/ip/commands lookingGlassType/ipv6 lookingGlassType/ipv6/adapters lookingGlassType/ipv6/commands lookingGlassType/metadata lookingGlassType/status lookingGlassType/status/adapters lookingGlassType/status/commands remote/common remote/ssh remote/telnet
  • Date: Tue, 8 Jan 2008 17:34:04 -0500

Author: stijn
Date: 2008-01-08 17:34:04 -0500 (Tue, 08 Jan 2008)
New Revision: 3194

Modified:

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/DbMetadataConfiguration.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/MetadataConfiguration.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java

trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
Log:
Redirected all output to the log-files so that a deployed SSH/Telnet MP
service does not write to catalina.out

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/BgpAdapterInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoBgpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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 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;
@@ -44,607 +43,555 @@
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
- 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("[CiscoBgpAdapter] 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.bgp.BgpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(BgpCommandInterface command) {

- }
+ logger.debug("[CiscoBgpAdapter] addAvailableSpecificCommand called");

- logger.debug("[CiscoBgpAdapter] Constructor started");
+ availableSpecificCommands.add(command);

- logger.debug("[CiscoBgpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {

- }// CiscoBgpAdapter
+ logger.debug("[CiscoBgpAdapter] 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("[CiscoBgpAdapter] getAvailableSpecificCommands
called");
+ command = (BgpCommand) it.next();

- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {

- }// getAvailableSpecificCommands
+ logger.debug("[CiscoBgpAdapter] Command found");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }

- logger.debug("[CiscoBgpAdapter] setAvailableSpecificCommand
called");
+ }// while

- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoBgpAdapter] 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("[CiscoBgpAdapter] executeCommand called");

- logger.debug("[CiscoBgpAdapter] addAvailableSpecificCommand
called");
+ if (manager != null) {

- availableSpecificCommands.add(command);
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());
+ String temp2 = manager.executeCommand(" ");

- }// addAvailableSpecificCommand
+ manager.disconnect();

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());

- logger.debug("[CiscoBgpAdapter] getCommand called");
+ }// if

- BgpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoBgpAdapter] executeCommand finished");
+ return command;

- while (it.hasNext()) {
+ }// executeCommand
+ public void connect() {
+ }

- command = (BgpCommand) it.next();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ logger.info("[CiscoBgpAdapter] Connect called");

- logger.debug("[CiscoBgpAdapter] 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"));

- logger.error("[CiscoBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ //System.out.println(username);
+ //System.out.println(password);

- }// getCommand
+ manager = new TelnetManager(url, port, false);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ }

- logger.debug("[CiscoBgpAdapter] executeCommand called");
+ logger.info("[CiscoBgpAdapter] 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.info("[CiscoBgpAdapter Login");

- manager.disconnect();
+ } catch (Exception e) {

- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ 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");

- }// if
+ }

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoBgpAdapter] 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("[CiscoBgpAdapter] Connect called");
+ public void setPort(int port) {

- try {
+ this.port = port;

- 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");
- caching =
Integer.parseInt(properties.getProperty(subject,"cache"));
+ public String getPrompt() {

- //System.out.println(username);
- //System.out.println(password);
+ return prompt;

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
-
.getProperty(subject,"prompt"));
+ }

- }
+ public void setPrompt(String prompt) {

- logger.info("[CiscoBgpAdapter] Trying to connect");
+ this.prompt = prompt;

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }

- logger.info("[CiscoBgpAdapter Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return url;

- 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) {

- }// 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("[CiscoBgpAdapter] 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("[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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+
logger.error("[CISCOBGPADAPTER][ConfigureCommands]"+e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[CiscoBgpAdapter] 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 {
+ String tempResult = temp.substring((bgpCommand.getCommand() + " "
+ bgpCommand.getParameterString()).length());

- logger.debug("[CiscoBgpAdapter] Configuring available
operations ...");
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- Iterator commands = 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, ' ');
+ }
+ }

- commands =
properties.getProperties(subject,"commands").iterator();
- while (commands.hasNext()) {
+ t2 = resultBuffer.toString();

- token = (String) commands.next();
- if (token.contains("BGP")) {
+ return t2.replace("" + prompt, "---END---");

- BgpCommand command = new
BgpCommand(token, properties
-
.getProperty(subject,token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject,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("[CiscoBgpAdapter] Webservice takeAction call received");

- logger.debug("[CiscoBgpAdapter] 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, BgpCommandInterface
bgpCommand) {
+ logger.debug("SUBJECTSTRING: " + subject);

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();

- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ CiscoBgpAdapter adapter = new CiscoBgpAdapter();

- String tempResult = temp
- .substring((bgpCommand.getCommand() + " " +
bgpCommand
-
.getParameterString()).length());
+ // REPLACED

- 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, ' ');
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- t2 = resultBuffer.toString();
+ manager = new TelnetManager(url, port, false);

- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {

- }
+
logger.error("[CISCOBGPADAPTER][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("[CISCOBGPADAPTER][TakeAction]"+e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- return this.serviceEngineType;
+ }

- }
+ logger.debug("[CiscoStatusAdapter] TelnetManager created: " + url +
" " + port);

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ try {

- logger.info("[CiscoBgpAdapter] 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("[CISCOBGPADAPTER][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("[CiscoStatusAdapter] 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);

- CiscoBgpAdapter adapter = new CiscoBgpAdapter();
- //adapter.connect(subject);
+ //

- // REPLACED
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);

- availableSpecificCommands = new ArrayList();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();

- try {
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; 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"));
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);

- manager = new TelnetManager(url, port, false);
+ 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.");
+ }

- } catch (NumberFormatException e1) {
+ }

- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {

- } catch (PerfSONARException e1) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ 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.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject, "prompt"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- } catch (PerfSONARException e) {
+ }

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ }

- }
+ if (temp.equalsIgnoreCase("")) {

- logger.debug("[CiscoStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ adapter.connect(subject);
+ temp = adapter.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.");
+ }

- 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("[CiscoBgpAdapter] Command executed succesfully");
+ logger.info("[CiscoBgpAdapter] 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("[CiscoBgpAdapter] Constructing response
message");
+ logger.info("[CiscoBgpAdapter] 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("[CiscoBgpAdapter] takeAction finished");
+ logger.info("[CiscoBgpAdapter] 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 {
+ CiscoBgpAdapter adapter = new CiscoBgpAdapter();

- try {
- CiscoBgpAdapter adapter = new CiscoBgpAdapter();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco1");

- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco1");
- //System.out.println("1");
+ adapter.connect("cisco1");

- adapter.connect("cisco1");
- //System.out.println("2");
+ BgpCommandInterface bgpCommand;

- BgpCommandInterface bgpCommand;
- //System.out.println("3");
+ try {

- try {
+ bgpCommand = adapter.getCommand("BGP");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);

- 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) {

- } catch (PerfSONARException e) {
+ //e.printStackTrace();

- e.printStackTrace();
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoKeyBgpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,586 +43,537 @@
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// 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"));

- }// while
+ manager = new SshKeyManager(url, username, keyUrl, false);

- logger.error("[CiscoKeyBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[CiscoKeyBgpAdapter] Trying to connect");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[CiscoKeyBgpAdapter] Login");

- logger.debug("[CiscoKeyBgpAdapter] executeCommand called");
+ } catch (Exception e) {

- if (manager != null) {
+ 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");
+ }

- 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.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }

- logger.info("[CiscoKeyBgpAdapter] Connect called");
+ public String getPrompt() {

- try {
+ return prompt;

- 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"));
+ public void setPrompt(String prompt) {

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ this.prompt = prompt;

- }
+ }

- logger.info("[CiscoKeyBgpAdapter] 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("[CiscoKeyBgpAdapter] Login");
+ return url;

- } catch (Exception e) {
+ }

- 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");
- }
+ 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("[CiscoKeyBgpAdapter] 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 {
+ 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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[CiscoKeyBgpAdapter][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[CiscoKeyBgpAdapter] 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 {
+ String tempResult = temp.substring((bgpCommand.getCommand() + " "
+ bgpCommand.getParameterString()).length());

- logger
- .debug("[CiscoKeyBgpAdapter] Configuring
available operations ...");
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- Iterator commands = 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, ' ');
+ }
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ t2 = resultBuffer.toString();

- token = (String) commands.next();
- if (token.contains("BGP")) {
+ return t2.replace("" + prompt, "---END---");

- 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) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoKeyBgpAdapter] Webservice takeAction call
received");

- logger.debug("[CiscoKeyBgpAdapter] 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, BgpCommandInterface
bgpCommand) {
+ logger.debug("SUBJECTSTRING: " + subject);

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();

- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();

- 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");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- 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);

- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {

- return t2.replace("" + prompt, "---END---");
+ logger.error("[CiscoKeyBgpAdapter][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("[CiscoKeyBgpAdapter][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("[CiscoKeyBgpAdapter] 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 {
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);

- logger
- .info("[CiscoKeyBgpAdapter] 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)) {
+ bgpCommand.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 (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {

- CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- //adapter.connect(subject);
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();

- availableSpecificCommands = new ArrayList();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{

- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- 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"));
+ } 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");
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();

- }
+ }

- logger.debug("[CiscoKeyBgpAdapter] 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 (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) {
+ adapter.connect(subject);
+ temp = adapter.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("[CiscoKeyBgpAdapter] Command executed succesfully");

- logger.info("[CiscoKeyBgpAdapter] 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("[CiscoKeyBgpAdapter] Constructing response message");

- logger.info("[CiscoKeyBgpAdapter] 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("[CiscoKeyBgpAdapter] takeAction finished");

- logger.info("[CiscoKeyBgpAdapter] takeAction finished");
+ return response;

- return response;
+ }

- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- // ---------------------- Stand-alond Test Method
+ try {
+ CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();

- 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 {
- CiscoKeyBgpAdapter adapter = new CiscoKeyBgpAdapter();
+ adapter.connect("junipernl");

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ BgpCommandInterface bgpCommand;

- adapter.connect("junipernl");
+ try {

- BgpCommandInterface bgpCommand;
+ bgpCommand = adapter.getCommand("BGP_PEERING_STATUS");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);

- try {
+ //System.out.println(adapter.filterResult(temp, bgpCommand));

- bgpCommand =
adapter.getCommand("BGP_PEERING_STATUS");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ } catch (PerfSONARException e) {

- System.out.println(adapter.filterResult(temp,
bgpCommand));
+ //e.printStackTrace();

- } catch (PerfSONARException e) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
- }
-
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/CiscoSshBgpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,581 +43,538 @@
*/
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 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 CiscoSshBgpAdapter() 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("[CISCOSSHBGPADAPTER][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 MetadataConfiguration properties = null;
-
- // ---------------------- caching attributes
+ logger.debug("[CiscoSshBgpAdapter] Constructor started");

- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoSshBgpAdapter] Constructor finished");

- // ---------------------- constructors
+ }// CiscoSshBgpAdapter

- public CiscoSshBgpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {

- try {
+ logger.debug("[CiscoSshBgpAdapter] getAvailableSpecificCommands
called");

- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
- 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("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] addAvailableSpecificCommand
called");

- logger.debug("[CiscoSshBgpAdapter] Constructor started");
+ availableSpecificCommands.add(command);

- logger.debug("[CiscoSshBgpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {

- }// CiscoSshBgpAdapter
+ logger.debug("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter]
getAvailableSpecificCommands called");
+ command = (BgpCommand) it.next();

- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {

- }// getAvailableSpecificCommands
+ logger.debug("[CiscoSshBgpAdapter] Command found");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }

- logger.debug("[CiscoSshBgpAdapter]
setAvailableSpecificCommand called");
+ }// while

- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] executeCommand called");

- logger.debug("[CiscoSshBgpAdapter]
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.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshBgpAdapter] executeCommand finished");
+ return command;

- logger.debug("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] Connect called");

- command = (BgpCommand) it.next();
+ try {

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {

- logger.debug("[CiscoSshBgpAdapter] 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"));

- }
+ //System.out.println(username);
+ //System.out.println(password);

- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- logger.error("[CiscoSshBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] executeCommand called");
+ logger.info("[CiscoSshBgpAdapter Login");

- if (manager != null) {
+ } catch (Exception e) {

- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ 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
+ }

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] Connect called");
+ public void setPort(int port) {

- try {
+ this.port = port;

- 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");
- caching =
Integer.parseInt(properties.getProperty(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("[CiscoSshBgpAdapter] Trying to connect");
+ this.prompt = prompt;

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }

- logger.info("[CiscoSshBgpAdapter Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return 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");
+ }

- }
+ 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("[CiscoSshBgpAdapter] 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("[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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[CISCOSSHBGPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[CiscoSshBgpAdapter] 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 {
+ String tempResult = temp;
+// .substring((bgpCommand.getCommand() + " " +
bgpCommand
+//
.getParameterString()).length());

- logger.debug("[CiscoSshBgpAdapter] Configuring available
operations ...");
+ String t1 = tempResult.replaceAll("\\n", "");
+ String t2 = t1.replaceAll("\\r", "@@@");

- Iterator commands = 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, ' ');
+ }
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ t2 = resultBuffer.toString();

- token = (String) commands.next();
- if (token.contains("BGP")) {
+ return t2.replace("" + prompt, "---END---");

- BgpCommand command = new
BgpCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoSshBgpAdapter] Webservice takeAction call
received");

- logger.debug("[CiscoSshBgpAdapter] 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, BgpCommandInterface
bgpCommand) {
+ logger.debug("SUBJECTSTRING: " + subject);

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();

- temp1 = temp.substring(0, temp.indexOf(" --More-- "));
- temp2 = temp.substring(temp.indexOf(" --More-- ") +
41);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();

- String tempResult = temp;
-// .substring((bgpCommand.getCommand() + " " +
bgpCommand
-//
.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"));

- return t2.replace("" + prompt, "---END---");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- }
+ } catch (NumberFormatException e1) {

- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOSSHBGPADAPTER][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("[CISCOSSHBGPADAPTER][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("[CiscoSshBgpAdapter] 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();
+ BgpCommandInterface bgpCommand = 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);

- CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();
- //adapter.connect(subject);
+ 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.");
+ }

- // REPLACED
+ }

- availableSpecificCommands = new ArrayList();
+ if (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {

- try {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- url = properties.getProperty(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();

- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.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);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();

- //
+ }

- BgpCommandInterface bgpCommand =
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 (bgpCommand.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);
+ BgpCommandInterface cachedCommand = (BgpCommandInterface)
it.next();

- 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.");
- }
+ 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();

- 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()) {
+ } 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();
-
- }
+ 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 (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()) {
+ if (temp.equalsIgnoreCase("")) {

- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(bgpCommand).getResult();
-
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).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.");

- //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);
+ logger.info("[CiscoSshBgpAdapter] Command executed succesfully");
+ logger.debug("" + valid);

- //System.out.println("[CiscoSshBgpAdapter] Constructing
response message");
- logger.info("[CiscoSshBgpAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, bgpCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] 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("[CiscoSshBgpAdapter] 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 {
- CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();
+ try {
+ CiscoSshBgpAdapter adapter = new CiscoSshBgpAdapter();

- //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");

- BgpCommandInterface bgpCommand;
+ BgpCommandInterface bgpCommand;

- try {
+ try {

- bgpCommand = adapter.getCommand("BGP");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- //System.out.println("Temp: " + temp);
+ bgpCommand = adapter.getCommand("BGP");
+ String temp = adapter.executeCommand(bgpCommand).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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperBgpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,610 +43,560 @@
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// 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"));

- }// getCommand
+ manager = new TelnetManager(url, port, false);
+ ((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(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"));
+ }

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject,
"prompt"));
+ public void setPrompt(String prompt) {

- }
+ this.prompt = prompt;

- logger.info("[JuniperBgpAdapter] Trying to connect");
+ }

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(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;

- Iterator commands = null;
- String token = null;
+ }

- try {
+ String tempResult = temp.substring((bgpCommand.getCommand() + " "
+ bgpCommand.getParameterString()).length());

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- token = (String) commands.next();
- if (token.contains("BGP")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- BgpCommand command = new
BgpCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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();

- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ JuniperBgpAdapter adapter = new JuniperBgpAdapter();

- 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);
+ // 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"));

- 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);

- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {

- return t2.replace("" + prompt, "---END---");
+ logger.error("[JUNIPERBGPADAPTER][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("[JUNIPERBGPADAPTER][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("[JuniperBgpAdapter] 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("[JuniperBgpAdapter] Webservice takeAction call
received");
+ } catch (PerfSONARException e) {

- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ logger.error("[JUNIPERBGPADAPTER][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("[JuniperBgpAdapter] 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);
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);

- JuniperBgpAdapter adapter = new JuniperBgpAdapter();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();

- //adapter.connect(subject);
+ 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.");
+ }

- // 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"));
+ }

- 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("[JuniperBgpAdapter] TelnetManager created: " +
url + " "
- + port);
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- try {
+ }

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(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("[JuniperBgpAdapter] 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) {

- 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) {
+ adapter.connect(subject);
+ temp = adapter.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("[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
+ public static void main(String[] args) {

- // ---------------------- Stand-alond Test Method
+ try {
+ JuniperBgpAdapter adapter = new JuniperBgpAdapter();

- 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 {
- JuniperBgpAdapter adapter = new JuniperBgpAdapter();
+ adapter.connect("juniper1");

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniper1");
+ BgpCommandInterface bgpCommand;

- adapter.connect("juniper1");
+ try {

- BgpCommandInterface bgpCommand;
+ bgpCommand = adapter.getCommand("BGP_MULTICAST_ROUTE");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);

- try {
+ //System.out.println(adapter.filterResult(temp, bgpCommand));

- bgpCommand =
adapter.getCommand("BGP_MULTICAST_ROUTE");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ } catch (PerfSONARException e) {

- System.out.println(adapter.filterResult(temp,
bgpCommand));
+ //e.printStackTrace();

- } catch (PerfSONARException e) {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperKeyBgpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,598 +43,551 @@
*/
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 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 MetadataConfiguration 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)
{

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] addAvailableSpecificCommand
called");

- }
+ availableSpecificCommands.add(command);

- logger.debug("[JuniperKeyBgpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public BgpCommandInterface getCommand(String description)
+ throws PerfSONARException {

- }// JuniperKeyBgpAdapter
+ logger.debug("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter]
getAvailableSpecificCommands called");
+ command = (BgpCommand) it.next();

- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {

- }// getAvailableSpecificCommands
+ logger.debug("[JuniperKeyBgpAdapter] Command found");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }

- logger
- .debug("[JuniperKeyBgpAdapter]
setAvailableSpecificCommand called");
+ }// while

- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] executeCommand called");

- logger
- .debug("[JuniperKeyBgpAdapter]
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 BgpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if

- logger.debug("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] Connect called");

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {

- logger.debug("[JuniperKeyBgpAdapter] 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"));

- }// while
+ manager = new SshKeyManager(url, username, keyUrl, false);

- logger.error("[JuniperKeyBgpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[JuniperKeyBgpAdapter] Trying to connect");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.BgpAdapterInterface
- */
- public BgpCommandInterface executeCommand(BgpCommandInterface
command) {
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[JuniperKeyBgpAdapter] Login");

- logger.debug("[JuniperKeyBgpAdapter] executeCommand called");
+ } catch (Exception e) {

- if (manager != null) {
+ 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");
+ }

- 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.bgp.BgpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }

- logger.info("[JuniperKeyBgpAdapter] Connect called");
+ public String getPrompt() {

- try {
+ return prompt;

- 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"));
+ public void setPrompt(String prompt) {

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ this.prompt = prompt;

- }
+ }

- logger.info("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] Login");
+ return url;

- } catch (Exception e) {
+ }

- 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");
- }
+ 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("[JuniperKeyBgpAdapter] 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 {
+ 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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[JUNIPERKEYBGPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] Configuring
available operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- Iterator commands = null;
- String token = null;
+ }

- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);

- token = (String) commands.next();
- if (token.contains("BGP")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- 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) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] 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();

- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ JuniperKeyBgpAdapter adapter = new JuniperKeyBgpAdapter();

- 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"));

- 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);

- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {

- return t2.replace("" + prompt, "---END---");
+ logger.error("[JUNIPERKEYBGPADAPTER][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("[JUNIPERKEYBGPADAPTER][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("[JuniperKeyBgpAdapter] 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 {
+ BgpCommandInterface bgpCommand = this.getCommand(eventTypeString);

- logger
- .info("[JuniperKeyBgpAdapter] 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)) {
+ bgpCommand.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 (bgpCommand.getParameters().size() >=
bgpCommand.getMinParamCount() && bgpCommand.getParameters().size() <=
bgpCommand.getMaxParamCount() && valid) {

- JuniperKeyBgpAdapter adapter = new JuniperKeyBgpAdapter();
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- //adapter.connect(subject);
+ BgpCommandInterface cachedCommand =
(BgpCommandInterface) it.next();

- availableSpecificCommands = new ArrayList();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(bgpCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(bgpCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(bgpCommand.getDeviceName()) &&
cachedCommand.getTimestamp() + (caching * 1000) > System.currentTimeMillis())
{

- try {
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- 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"));
+ } 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");
+ adapter.connect(subject);
+ temp = adapter.executeCommand(bgpCommand).getResult();

- }
+ }

- logger.debug("[JuniperKeyBgpAdapter] 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 (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) {
+ adapter.connect(subject);
+ temp = adapter.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("[JuniperKeyBgpAdapter] Command executed succesfully");

- logger.info("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] Constructing response message");

- logger.info("[JuniperKeyBgpAdapter] 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("[JuniperKeyBgpAdapter] takeAction finished");

- logger.info("[JuniperKeyBgpAdapter] takeAction finished");
+ return response;

- return response;
+ }

- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- // ---------------------- Stand-alond Test Method
+ try {
+ JuniperKeyBgpAdapter adapter = new JuniperKeyBgpAdapter();

- 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 {
- JuniperKeyBgpAdapter adapter = new
JuniperKeyBgpAdapter();
+ adapter.connect("junipernl");

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ BgpCommandInterface bgpCommand;

- adapter.connect("junipernl");
+ try {

- BgpCommandInterface bgpCommand;
+ bgpCommand = adapter.getCommand("BGP_PEERING_STATUS");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);

- try {
+ //System.out.println(adapter.filterResult(temp, bgpCommand));

- bgpCommand =
adapter.getCommand("BGP_PEERING_STATUS");
- String temp =
adapter.executeCommand(bgpCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ } catch (PerfSONARException e) {

- System.out.println(adapter.filterResult(temp,
bgpCommand));
+ //e.printStackTrace();

- } catch (PerfSONARException e) {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/adapters/JuniperSshBgpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,593 +43,553 @@
*/
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 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 MetadataConfiguration 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");

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ 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"));

- }
+ //System.out.println(username);
+ //System.out.println(password);

- }// while
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- 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(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"));
+ 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;

- Iterator commands = null;
- String token = null;
+ }

- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);

- token = (String) commands.next();
- if (token.contains("BGP")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- BgpCommand command = new
BgpCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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();

- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ JuniperSshBgpAdapter adapter = new JuniperSshBgpAdapter();

- 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"));

- t2 = resultBuffer.toString();
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- 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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(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);
+ adapter.connect(subject);
+ temp = adapter.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.");
+ }

- 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("[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
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- public static void main(String[] args) {
+ try {
+ JuniperSshBgpAdapter adapter = new JuniperSshBgpAdapter();

- try {
- JuniperSshBgpAdapter adapter = new
JuniperSshBgpAdapter();
+ //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");
+ BgpCommandInterface bgpCommand;

- BgpCommandInterface bgpCommand;
+ try {

- try {
+ bgpCommand = adapter.getCommand("BGP");
+ String temp = adapter.executeCommand(bgpCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);

- bgpCommand = adapter.getCommand("BGP");
- String temp =
adapter.executeCommand(bgpCommand).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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommand.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/bgp/commands/BgpCommandInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/encryption/PasswordEncryptor.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,16 +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;
import javax.crypto.IllegalBlockSizeException;
@@ -18,113 +15,130 @@
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
-
import org.apache.ws.security.util.Base64;

+/**
+ * Class for encrypting and decrypting plain-text password fields in the
+ * metadataconfiguration-file.
+ *
+ * @author smelis
+ */
public class PasswordEncryptor {
+

- public static String encryptPassword (String pass) {
+ /**
+ * Encrypting the supplied parameter
+ *
+ * @param pass
+ * @return String encryptedPassword
+ */
+ public static String encryptPassword(String pass) {
+
+ String result = "";

- String result = "";
+ // Encrypt the cleartext
+ byte[] ciphertext;

- // Encrypt the cleartext
- byte[] ciphertext;
+ try {
+ // Create an array to hold the key
+ byte[] encryptKey = "This is a test DESede key".getBytes();

- try {
- // Create an array to hold the key
- byte[] encryptKey = "This is a test DESede
key".getBytes();
+ // Create a DESede key spec from the key
+ DESKeySpec spec = new DESKeySpec(encryptKey);

- // Create a DESede key spec from the key
- DESKeySpec spec = new DESKeySpec(encryptKey);
+ SecretKeyFactory keyfact = SecretKeyFactory.getInstance("DES");

- SecretKeyFactory keyfact =
SecretKeyFactory.getInstance("DES");
+ SecretKey desKey = keyfact.generateSecret(spec);

- SecretKey desKey = keyfact.generateSecret(spec);
+ Cipher desCipher;

- Cipher desCipher;
+ // Create the cipher
+ desCipher = Cipher.getInstance("DES");

- // Create the cipher
- desCipher = Cipher.getInstance("DES");
+ // Initialize the cipher for encryption
+ desCipher.init(Cipher.ENCRYPT_MODE, desKey);

- // Initialize the cipher for encryption
- desCipher.init(Cipher.ENCRYPT_MODE, desKey);
+ // Our cleartext
+ byte[] cleartext = pass.getBytes("ISO-8859-1");

- // Our cleartext
- byte[] cleartext = pass.getBytes("ISO-8859-1");
-
- ciphertext = desCipher.doFinal(cleartext);
+ ciphertext = desCipher.doFinal(cleartext);

- return Base64.encode(ciphertext);
+ return Base64.encode(ciphertext);

- //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;
- }
+ //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;
+ }

+ /**
+ * Decrypting the supplied parameter into a plain-text version
+ *
+ * @param pass
+ * @return String plain-text password
+ */
+ public static String decryptPassword(String pass) {
+ String result = "";

- public static String decryptPassword (String pass) {
- String result = "";
+ try {
+ // Create an array to hold the key
+ byte[] encryptKey = "This is a test DESede key".getBytes();

- try {
- // Create an array to hold the key
- byte[] encryptKey = "This is a test DESede
key".getBytes();
+ // Create a DESede key spec from the key
+ DESKeySpec spec = new DESKeySpec(encryptKey);

- // Create a DESede key spec from the key
- DESKeySpec spec = new DESKeySpec(encryptKey);
+ SecretKeyFactory keyfact = SecretKeyFactory.getInstance("DES");

- SecretKeyFactory keyfact =
SecretKeyFactory.getInstance("DES");
+ SecretKey desKey = keyfact.generateSecret(spec);

- SecretKey desKey = keyfact.generateSecret(spec);
+ Cipher desCipher;

- Cipher desCipher;
+ // Create the cipher
+ desCipher = Cipher.getInstance("DES");

- // Create the cipher
- desCipher = Cipher.getInstance("DES");
+ // Initialize the same cipher for decryption
+ desCipher.init(Cipher.DECRYPT_MODE, desKey);

- // Initialize the same cipher for decryption
- desCipher.init(Cipher.DECRYPT_MODE, desKey);
+ //byte[] encrypted = pass.getBytes("ISO-8859-1");
+ byte[] encrypted = Base64.decode(pass);

- //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] + ")");
+ //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] + ")");

- // Decrypt the ciphertext
- byte[] cleartext1 = desCipher.doFinal(encrypted);
+ // Decrypt the ciphertext
+ byte[] cleartext1 = desCipher.doFinal(encrypted);

- 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();
- }
+ 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();
+ }

- return result;
- }
+ return result;
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -43,169 +43,158 @@
*/
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 MetadataConfiguration properties = null;
+ try {

- private CiscoIpAdapter ciscoIpAdapter = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);

- private CiscoIpv6Adapter ciscoIpv6Adapter = null;
-
- private CiscoStatusAdapter ciscoStatusAdapter = null;
-
- private CiscoBgpAdapter ciscoBgpAdapter = null;
-
- // ---------------------- constructors
-
- public CiscoAdapter() throws PerfSONARException {
-
- try {
-
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
-
this.properties = new DbMetadataConfiguration();
properties.initStorage();

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";

- ciscoIpAdapter = new CiscoIpAdapter();
- ciscoIpv6Adapter = new CiscoIpv6Adapter();
- ciscoStatusAdapter = new CiscoStatusAdapter();
- ciscoBgpAdapter = new CiscoBgpAdapter();
+ ciscoIpAdapter = new CiscoIpAdapter();
+ ciscoIpv6Adapter = new CiscoIpv6Adapter();
+ ciscoStatusAdapter = new CiscoStatusAdapter();
+ ciscoBgpAdapter = new CiscoBgpAdapter();

- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e) {

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
+ 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.");
+ }

- }//CiscoAdapter
+ }//CiscoAdapter

- // ---------------------- Methods from service engine interface
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {

- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ return this.serviceEngineType;

- return this.serviceEngineType;
+ }

- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.info("[CiscoAdapter] Webservice takeAction call received");

- logger.info("[CiscoAdapter] Webservice takeAction call
received");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject subject = metadata[0].getSubject();
+ EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
+ String subjectString = endpoint.getValue();

- Metadata[] metadata = request.getMetadataArray();
- Subject subject = metadata[0].getSubject();
- EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
- String subjectString = endpoint.getValue();
+ logger.debug("SUBJECTSTRING: " + subjectString);

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ EventType eventType = null;
+ String eventTypeString = "";
+ try {
+ eventType = metadata[0].getEventType();
+ eventTypeString = eventType.getEventType();
+ } catch (Exception e) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.command",
+ "No Command/EventType specified in 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");
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- //System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ long last = 0;

- long last = 0;
+ 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);

- String rate;
- try {
- rate = properties.getProperty(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);
+ try {
+ FileInputStream in = new FileInputStream("token_" +
subjectString);
+ ObjectInputStream is = new ObjectInputStream(in);
+ last = is.readLong();
+ is.close();

- try {
- FileInputStream in = new FileInputStream("token_" +
subjectString);
- ObjectInputStream is = new ObjectInputStream(in);
- last = is.readLong();
- is.close();
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e) {

- FileOutputStream out = new FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e) {
+ 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");
+ }

- 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");
- }
+ //e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("[CISCOADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ }

- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ if (System.currentTimeMillis() - last > rateLong) {

- if (System.currentTimeMillis() - last > rateLong) {
+ if (eventTypeString.contains("IP_")) {

- if (eventTypeString.contains("IP_")) {
+ return this.ciscoIpAdapter.takeAction(actionType, request);

- return
this.ciscoIpAdapter.takeAction(actionType, request);
+ } else if (eventTypeString.contains("IPv6")) {

- } else if (eventTypeString.contains("IPv6")) {
+ return this.ciscoIpv6Adapter.takeAction(actionType, request);

- return
this.ciscoIpv6Adapter.takeAction(actionType, request);
+ } else if (eventTypeString.contains("STATUS_")) {

- } else if (eventTypeString.contains("STATUS_")) {
+ return this.ciscoStatusAdapter.takeAction(actionType,
request);

- return
this.ciscoStatusAdapter.takeAction(actionType, request);
+ } else if (eventTypeString.contains("BGP")) {

- } else if (eventTypeString.contains("BGP")) {
+ return this.ciscoBgpAdapter.takeAction(actionType, request);

- return
this.ciscoBgpAdapter.takeAction(actionType, request);
+ } else {

- } else {
+ throw new PerfSONARException("error.mp.sshtelnet.request",
+ "[CiscoAdapter] Request not supported by this
device");

- throw new
PerfSONARException("error.mp.sshtelnet.request",
- "[CiscoAdapter] Request not
supported by this device");
+ }

- }
+ } else {

- } else {
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Too many requests");

- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Too many requests");
+ }

- }
-
- }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoKeyAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -43,171 +43,159 @@
*/
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 MetadataConfiguration properties = null;
+ try {

- private CiscoKeyIpAdapter ciscoKeyIpAdapter = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);

- private CiscoKeyIpv6Adapter ciscoKeyIpv6Adapter = null;
-
- private CiscoKeyStatusAdapter ciscoKeyStatusAdapter = null;
-
- private CiscoKeyBgpAdapter ciscoKeyBgpAdapter = null;
-
- // ---------------------- constructors
-
- public CiscoKeyAdapter() throws PerfSONARException {
-
- try {
-
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
-
this.properties = new DbMetadataConfiguration();
properties.initStorage();

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";

- ciscoKeyIpAdapter = new CiscoKeyIpAdapter();
- ciscoKeyIpv6Adapter = new CiscoKeyIpv6Adapter();
- ciscoKeyStatusAdapter = new CiscoKeyStatusAdapter();
- ciscoKeyBgpAdapter = new CiscoKeyBgpAdapter();
+ ciscoKeyIpAdapter = new CiscoKeyIpAdapter();
+ ciscoKeyIpv6Adapter = new CiscoKeyIpv6Adapter();
+ ciscoKeyStatusAdapter = new CiscoKeyStatusAdapter();
+ ciscoKeyBgpAdapter = new CiscoKeyBgpAdapter();

- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e) {

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
+ 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.");
+ }

- }//JuniperAdapter
+ }//JuniperAdapter

- // ---------------------- Methods from service engine interface
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {

- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ return this.serviceEngineType;

- return this.serviceEngineType;
+ }

- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.info("[JuniperAdapter] Webservice takeAction call received");

- logger.info("[JuniperAdapter] Webservice takeAction call
received");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject subject = metadata[0].getSubject();
+ EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
+ String subjectString = endpoint.getValue();

- Metadata[] metadata = request.getMetadataArray();
- Subject subject = metadata[0].getSubject();
- EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
- String subjectString = endpoint.getValue();
+ logger.debug("SUBJECTSTRING: " + subjectString);

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ EventType eventType = null;
+ String eventTypeString = "";
+ try {
+ eventType = metadata[0].getEventType();
+ eventTypeString = eventType.getEventType();
+ } catch (Exception e) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.command",
+ "No Command/EventType specified in 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");
- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
+ long last = 0;

- //System.out.println("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);

- String rate;
- try {
- rate = properties.getProperty(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);
+ try {
+ FileInputStream in = new FileInputStream("token_" +
subjectString);
+ ObjectInputStream is = new ObjectInputStream(in);
+ last = is.readLong();
+ is.close();

- try {
- FileInputStream in = new FileInputStream("token_" +
subjectString);
- ObjectInputStream is = new ObjectInputStream(in);
- last = is.readLong();
- is.close();
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e) {

- FileOutputStream out = new FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e) {
+ 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");
+ }

- 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");
- }
+ //e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("[CISCOKEYADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ }

- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ if (System.currentTimeMillis() - last > rateLong) {

- if (System.currentTimeMillis() - last > rateLong) {
+ if (eventTypeString.contains("IP_")) {

- if (eventTypeString.contains("IP_")) {
+ return this.ciscoKeyIpAdapter.takeAction(actionType,
request);

- return
this.ciscoKeyIpAdapter.takeAction(actionType, request);
+ } else if (eventTypeString.contains("IPv6")) {

- } else if (eventTypeString.contains("IPv6")) {
+ return this.ciscoKeyIpv6Adapter.takeAction(actionType,
+ request);

- return
this.ciscoKeyIpv6Adapter.takeAction(actionType,
- request);
+ } else if (eventTypeString.contains("STATUS_")) {

- } else if (eventTypeString.contains("STATUS_")) {
+ return this.ciscoKeyStatusAdapter.takeAction(actionType,
+ request);

- return
this.ciscoKeyStatusAdapter.takeAction(actionType,
- request);
+ } else if (eventTypeString.contains("BGP")) {

- } else if (eventTypeString.contains("BGP")) {
+ return this.ciscoKeyBgpAdapter.takeAction(actionType,
request);

- return this.ciscoKeyBgpAdapter
- .takeAction(actionType,
request);
+ } else {

- } else {
+ throw new PerfSONARException("error.mp.sshtelnet.request",
+ "[JuniperKeyAdapter] Request not supported by this
device");

- throw new
PerfSONARException("error.mp.sshtelnet.request",
- "[JuniperKeyAdapter] Request
not supported by this device");
+ }

- }
+ } else {

- } else {
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Too many requests");

- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Too many requests");
+ }

- }
-
- }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/CiscoSshAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -83,7 +83,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.");
}
@@ -114,7 +114,7 @@
EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
String subjectString = endpoint.getValue();

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subjectString);

EventType eventType = null;
String eventTypeString = "";
@@ -122,20 +122,20 @@
eventType = metadata[0].getEventType();
eventTypeString = eventType.getEventType();
} 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(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 +161,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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -43,170 +43,158 @@
*/
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 MetadataConfiguration properties = null;
+ try {

- private JuniperIpAdapter juniperIpAdapter = null;
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);

- private JuniperIpv6Adapter juniperIpv6Adapter = null;
-
- private JuniperStatusAdapter juniperStatusAdapter = null;
-
- private JuniperBgpAdapter juniperBgpAdapter = null;
-
- // ---------------------- constructors
-
- public JuniperAdapter() throws PerfSONARException {
-
- try {
-
- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
-
this.properties = new DbMetadataConfiguration();
properties.initStorage();

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";

- juniperIpAdapter = new JuniperIpAdapter();
- juniperIpv6Adapter = new JuniperIpv6Adapter();
- juniperStatusAdapter = new JuniperStatusAdapter();
- juniperBgpAdapter = new JuniperBgpAdapter();
+ juniperIpAdapter = new JuniperIpAdapter();
+ juniperIpv6Adapter = new JuniperIpv6Adapter();
+ juniperStatusAdapter = new JuniperStatusAdapter();
+ juniperBgpAdapter = new JuniperBgpAdapter();

- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e) {

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
- }
+ 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.");
+ }

- }//JuniperAdapter
+ }//JuniperAdapter

- // ---------------------- Methods from service engine interface
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {

- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ return this.serviceEngineType;

- return this.serviceEngineType;
+ }

- }
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.info("[JuniperAdapter] Webservice takeAction call received");

- logger.info("[JuniperAdapter] Webservice takeAction call
received");
+ Metadata[] metadata = request.getMetadataArray();
+ Subject subject = metadata[0].getSubject();
+ EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
+ String subjectString = endpoint.getValue();

- Metadata[] metadata = request.getMetadataArray();
- Subject subject = metadata[0].getSubject();
- EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
- String subjectString = endpoint.getValue();
+ logger.debug("SUBJECTSTRING: " + subjectString);

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ EventType eventType = null;
+ String eventTypeString = "";
+ try {
+ eventType = metadata[0].getEventType();
+ eventTypeString = eventType.getEventType();
+ } catch (Exception e) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.command",
+ "No Command/EventType specified in 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");
- }

+ logger.debug("EVENTTYPESTRING: " + eventTypeString);
+ long last = 0;

- //System.out.println("EVENTTYPESTRING: " + eventTypeString);

- long last = 0;
+ 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);

- String rate;
- try {
- rate = properties.getProperty(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);
+ try {
+ FileInputStream in = new FileInputStream("token_" +
subjectString);
+ ObjectInputStream is = new ObjectInputStream(in);
+ last = is.readLong();
+ is.close();

- try {
- FileInputStream in = new FileInputStream("token_" +
subjectString);
- ObjectInputStream is = new ObjectInputStream(in);
- last = is.readLong();
- is.close();
+ FileOutputStream out = new FileOutputStream("token_" +
subjectString);
+ ObjectOutputStream s = new ObjectOutputStream(out);
+ s.writeLong(System.currentTimeMillis());
+ s.flush();
+ } catch (FileNotFoundException e) {

- FileOutputStream out = new FileOutputStream("token_"
- + subjectString);
- ObjectOutputStream s = new ObjectOutputStream(out);
- s.writeLong(System.currentTimeMillis());
- s.flush();
- } catch (FileNotFoundException e) {
+ 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");
+ }

- 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");
- }
+ //e.printStackTrace();
+ } catch (IOException e) {
+ logger.error("[JUNIPERADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ }

- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ if (System.currentTimeMillis() - last > rateLong) {

- if (System.currentTimeMillis() - last > rateLong) {
+ if (eventTypeString.contains("IP_")) {

- if (eventTypeString.contains("IP_")) {
+ return this.juniperIpAdapter.takeAction(actionType, request);

- return
this.juniperIpAdapter.takeAction(actionType, request);
+ } else if (eventTypeString.contains("IPv6")) {

- } else if (eventTypeString.contains("IPv6")) {
+ return this.juniperIpv6Adapter.takeAction(actionType,
request);

- return
this.juniperIpv6Adapter.takeAction(actionType, request);
+ } else if (eventTypeString.contains("STATUS_")) {

- } else if (eventTypeString.contains("STATUS_")) {
+ return this.juniperStatusAdapter.takeAction(actionType,
request);

- return this.juniperStatusAdapter
- .takeAction(actionType,
request);
+ } else if (eventTypeString.contains("BGP")) {

- } else if (eventTypeString.contains("BGP")) {
+ return this.juniperBgpAdapter.takeAction(actionType,
request);

- return
this.juniperBgpAdapter.takeAction(actionType, request);
+ } else {

- } else {
+ throw new PerfSONARException("error.mp.sshtelnet.request",
+ "[JuniperAdapter] Request not supported by this
device");

- throw new
PerfSONARException("error.mp.sshtelnet.request",
- "[JuniperAdapter] Request not
supported by this device");
+ }

- }
+ } else {

- } else {
+ throw new PerfSONARException("error.mp.sshtelnet.token",
+ "Too many requests");

- throw new
PerfSONARException("error.mp.sshtelnet.token",
- "Too many requests");
+ }

- }
-
- }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperKeyAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -83,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.");
}
@@ -114,7 +114,7 @@
EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
String subjectString = endpoint.getValue();

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subjectString);

EventType eventType = null;
String eventTypeString = "";
@@ -122,20 +122,20 @@
eventType = metadata[0].getEventType();
eventTypeString = eventType.getEventType();
} 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(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 +161,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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/JuniperSshAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -83,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.");
}
@@ -114,7 +114,7 @@
EndPoint endpoint = (EndPoint) subject.getChildArray()[0];
String subjectString = endpoint.getValue();

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ logger.debug("SUBJECTSTRING: " + subjectString);

EventType eventType = null;
String eventTypeString = "";
@@ -122,20 +122,20 @@
eventType = metadata[0].getEventType();
eventTypeString = eventType.getEventType();
} 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(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 +161,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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestExecutingThread.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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 org.ggf.ns.nmwg.base.v2_0.Data;
@@ -10,124 +18,123 @@
import org.perfsonar.service.base.engine.ServiceEngine;
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;

- 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;

- Subject resultCodeSubject = new Subject();
- resultCodeSubject.setId("resultCodeSubj_"
- + requestMetadata.getId());
-
resultCodeSubject.setMetadataIdRef(requestMetadata.getId());
+ }

- EventType resultCodeEventType = new EventType();
- resultCodeEventType.setId("resultCodeEventType_"
- + requestMetadata.getId());
-
resultCodeEventType.setEventType("success.mp.sshtelnet");
+ /**
+ * Retrieve the result and compose it into an XML compliant
+ * document
+ */
+ public void run() {
+ try {
+ ServiceEngine serviceEngine =
ServiceEngineFactory.getServiceEngine(serviceEngineString);
+ resultMessage = serviceEngine.takeAction(actionType,
requestMessage);

- resultCodeMetadata.addChild(resultCodeSubject);
- resultCodeMetadata.addChild(resultCodeEventType);
+ // Inclusion of the result code tags
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
requestMetadata.getId());

- Data resultCodeData = new Data();
- resultCodeData
- .setId("resultCodeData_" +
requestMetadata.getId());
- resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + requestMetadata.getId());
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
requestMetadata.getId());
+ resultCodeSubject.setMetadataIdRef(requestMetadata.getId());

- Datum resultCodeDatum = new Datum();
- resultCodeDatum.setId("resultCodeDatum_"
- + requestMetadata.getId());
- resultCodeDatum.setValue("Successfully executed
request");
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
requestMetadata.getId());
+ resultCodeEventType.setEventType("success.mp.sshtelnet");

- resultCodeData.addChild(resultCodeDatum);
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);

- resultMessage.setMetadata(resultCodeMetadata);
- resultMessage.setData(resultCodeData);
-
- } 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("Successfully executed request");

- 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());
+ //Something went wrong during the retrieval process.
+ //Constructing the XML-compliant error message
+ } catch (PerfSONARException e) {

- EventType resultCodeEventType = new EventType();
- resultCodeEventType.setId("resultCodeEventType_"
- + requestMetadata.getId());
- resultCodeEventType.setEventType(e.getResultCode());
+ 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(e.getResultDescription());
+ 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);

- }
-
- requestMonitor.setCompleted(id, resultMessage);
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/RequestMonitor.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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 org.ggf.ns.nmwg.base.v2_0.Message;
@@ -2,51 +10,80 @@

+/**
+ * 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 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;
-
- }
+ 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;
+ }
+
+ 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;
+
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -22,1126 +30,1101 @@
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 {

- private static Namespace NMWG = Namespace.getNamespace("nmwg",
"http://ggf.org/ns/nmwg/base/2.0/";);
+ private static Namespace NMWG = Namespace.getNamespace("nmwg",
"http://ggf.org/ns/nmwg/base/2.0/";);
+ String[] lines;
+ String previousDevices;

- String[] lines;
+ //private Properties prop;
+ Document doc;
+ Element store;
+ Element metadata;
+ Element data;
+ private static String MINIMUM_PACKAGE = "minimumpackage.txt";

- String previousDevices;
+ public ServicePropertiesConfigurator() {
+ lines = new String[3];
+ //prop = new Properties();
+ }

- //private Properties prop;
- Document doc;
- Element store;
- Element metadata;
- Element data;
+ public void doStuff(String outputFile) {

- private static String MINIMUM_PACKAGE = "minimumpackage.txt";
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));

- public ServicePropertiesConfigurator() {
- lines = new String[3];
- //prop = new Properties();
- }
+ doc = new Document();
+ store = new Element("store", NMWG);

- public void doStuff(String outputFile) {

- try {
- BufferedReader br = new BufferedReader(new
InputStreamReader(
- System.in));
+ previousDevices = new String(); // devices defined in given
service.properties file

- doc = new Document();
- store = new Element("store", NMWG);
-
+ File outpFile = new File(outputFile);

- previousDevices = new String(); // devices defined
in given service.properties file
+ /*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("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();
+ }

- /*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();
+ 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
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();
- }
+ SAXBuilder builder = new SAXBuilder();
+ doc = builder.build(file);

- 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();
-
- SAXBuilder builder = new SAXBuilder();
- doc = builder.build(file);
-
- store = doc.getRootElement();
-
- } catch (JDOMException e) {
- System.out.println("[ERROR] entered
configuration file does not exist");
- e.printStackTrace();
- }
+ store = doc.getRootElement();

- } 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();
- }
+ } catch (JDOMException e) {
+ System.out.println("[ERROR] entered configuration file
does not exist");
+ e.printStackTrace();
+ }

- 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
+ 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();
+ }

- parseCSVFile(previous, outputFile);
+ 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...");

- System.out.println("Parsing done.");
+ parseCSVFile(previous, outputFile);

- } else { // answer == no
+ System.out.println("Parsing done.");

- askManually(outputFile); // manually
provide configuration information
- }
- }
+ } else { // answer == no

- doc.setRootElement(store);
-
- 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");
+ askManually(outputFile); // manually provide
configuration information
+ }
+ }

- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ doc.setRootElement(store);

- private void parseCSVFile(String file, String outputFile) {
- try {
- // Read all lines from txt file
- lines = readLinesFromFile(file);
+ 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");

- StringTokenizer tok;
- StringTokenizer deviceTok;
- String deviceInfo;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }

- String device;
- String deviceType;
- //String[] devicesArray = new String[lines.length];
-
- //System.out.println("[DEBUG] number of lines to be
parsed: " + lines.length);
-
- for (int i=0; i<lines.length && lines[i] != null;
i++){
+ private void parseCSVFile(String file, String outputFile) {
+ try {
+ // Read all lines from txt file
+ lines = readLinesFromFile(file);

- //System.out.println("[DEBUG] line:
"+lines[i]);
-
- metadata = new Element("metadata", NMWG);
- metadata.setAttribute("id", "metadata" + i);
+ StringTokenizer tok;
+ StringTokenizer deviceTok;
+ String deviceInfo;

- tok = new StringTokenizer(lines[i],"%%%");
+ String device;
+ String deviceType;
+ //String[] devicesArray = new String[lines.length];

- // First the device info
- deviceInfo = tok.nextToken();
- deviceTok = new
StringTokenizer(deviceInfo,"@@@");
- device = deviceTok.nextToken();
+ //System.out.println("[DEBUG] number of lines to be parsed: " +
lines.length);

- Element subject = new Element("subject",
NMWG);
- subject.setAttribute("id", "subject"+i);
- subject.addContent(device);
- metadata.addContent(subject);
+ for (int i = 0; i < lines.length && lines[i] != null; i++) {

- //devicesArray[i] = device;
- deviceType = deviceTok.nextToken();
+ //System.out.println("[DEBUG] line: "+lines[i]);

- Element params = new Element("parameters",
NMWG);
- params.setAttribute("id", "metaParams"+i);
+ metadata = new Element("metadata", NMWG);
+ metadata.setAttribute("id", "metadata" + i);

- Element param;
+ tok = new StringTokenizer(lines[i], "%%%");

- 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","cache");
- param.setAttribute("value", "0");
- params.addContent(param);
+ // First the device info
+ deviceInfo = tok.nextToken();
+ deviceTok = new StringTokenizer(deviceInfo, "@@@");
+ device = deviceTok.nextToken();

- 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","cache");
- param.setAttribute("value","0");
- params.addContent(param);
+ Element subject = new Element("subject", NMWG);
+ subject.setAttribute("id", "subject" + i);
+ subject.addContent(device);
+ metadata.addContent(subject);

- 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);
- 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);
+ //devicesArray[i] = device;
+ deviceType = deviceTok.nextToken();

- 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","cache");
- param.setAttribute("value","0");
- params.addContent(param);
+ Element params = new Element("parameters", NMWG);
+ params.setAttribute("id", "metaParams" + i);

- 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","cache");
- param.setAttribute("value","0");
- params.addContent(param);
+ Element param;

- 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);
- 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);
-
- metadata.addContent(params);
- } else {
- System.out.println("There was an
unknown device type in the csv file: "+deviceType);
- }
+ 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", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);

- store.addContent(metadata);
+ 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", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);

-
- File tempFile =
File.createTempFile(device+"commands", ".tmp");
- DataOutputStream dos = new
DataOutputStream(new FileOutputStream(tempFile, true));
+ 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);
+ 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);

- while (tok.hasMoreTokens()) {
- //Then write all command info to a
temporary file
- String s = tok.nextToken();
- dos.writeBytes(s+"\n");
- dos.flush();
- }
+ 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", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);

- dos.close();
-
- data = new Element("data", NMWG);
- data.setAttribute("id", "data" + i);
- data.setAttribute("metadataIdRef", "metadata"
+ i);
-
-
- //Then use this temporary file for writing
all command info
- addSelectedCommandsToConfig(device,
outputFile, tempFile.toString());
-
- store.addContent(data);
-
-
- }
+ 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", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);

- /*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();
- }
- }
+ 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);
+ 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);

- private String[] readLinesFromFile(String file) {
- ArrayList<String> lines = new ArrayList<String>();
+ metadata.addContent(params);
+ } else {
+ System.out.println("There was an unknown device type in
the csv file: " + deviceType);
+ }

- 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();
- }
+ store.addContent(metadata);

- return lines.toArray(this.lines);
- }

- private void askManually(String outputFile) {
- try{
- BufferedReader br = new BufferedReader(new
InputStreamReader(
- System.in));
+ File tempFile = File.createTempFile(device + "commands",
".tmp");
+ DataOutputStream dos = new DataOutputStream(new
FileOutputStream(tempFile, true));

- List devices = new ArrayList();
+ while (tok.hasMoreTokens()) {
+ //Then write all command info to a temporary file
+ String s = tok.nextToken();
+ dos.writeBytes(s + "\n");
+ dos.flush();
+ }

- List types = new ArrayList();
+ dos.close();

- 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);
- }
+ data = new Element("data", NMWG);
+ data.setAttribute("id", "data" + i);
+ data.setAttribute("metadataIdRef", "metadata" + i);

- if (devices.size() > 0) {
- Iterator it = devices.iterator();
- System.out.println(devices.size() + " devices
added.");

- 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();
+ //Then use this temporary file for writing all command info
+ addSelectedCommandsToConfig(device, outputFile,
tempFile.toString());

- 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 <= 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();
+ store.addContent(data);

- 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);

- System.out.println(device);
- System.out.println("======");
- System.out.println();
+ }

- metadata = new Element("metadata",
NMWG);
- metadata.setAttribute("id",
"metadata"+index);
-
- Element subject = new Element
("subject", NMWG);
- subject.setAttribute("id",
"subject0");
- subject.addContent(device);
+ /*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();
+ }
+ }

- metadata.addContent(subject);
-
- Element params = new
Element("parameters", NMWG);
- params.setAttribute("id",
"metaParams0");
-
- Element param;
-
- if (type.equalsIgnoreCase("1")
- ||
type.equalsIgnoreCase("2")
- ||
type.equalsIgnoreCase("4")
- ||
type.equalsIgnoreCase("5")) {
-
- 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();
- 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 + ":
");
- 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);
-
- param = new
Element("parameter", NMWG);
- param.setAttribute("name",
"cache");
- param.setAttribute("value",
"0");
- params.addContent(param);
-

- metadata.addContent(params);
- } else if (type.equalsIgnoreCase("3")
- ||
type.equalsIgnoreCase("6")) {
-
- 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);
-
- } 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();
- 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 + ":
");
- 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();
-
- if (input != null &&
!input.equals("")){
- param = new
Element("parameter", NMWG);
-
param.setAttribute("name","passphrase");
-
param.setAttribute("value", PasswordEncryptor.encryptPassword(input));
-
params.addContent(param);
-
- }
-
- param = new
Element("parameter", NMWG);
- param.setAttribute("name",
"cache");
- param.setAttribute("value",
"0");
- params.addContent(param);
-
- metadata.addContent(params);
- }
+ private String[] readLinesFromFile(String file) {
+ ArrayList<String> lines = new ArrayList<String>();

- store.addContent(metadata);
-
- System.out.println();
+ 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();
+ }

+ return lines.toArray(this.lines);
+ }

- 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();
- }
+ private void askManually(String outputFile) {
+ try {
+ BufferedReader br = new BufferedReader(new InputStreamReader(
+ System.in));

- if (input.equals("yes")){ // use
predefined set
+ List devices = new ArrayList();

+ List types = new ArrayList();

- 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;
- }
- }
+ 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);
+ }
+ }

- File tempFile =
File.createTempFile(device+"minimum", ".tmp");
+ if (devices.size() > 0) {
+ Iterator it = devices.iterator();
+ System.out.println(devices.size() + " devices added.");

- DataOutputStream tempout =
new DataOutputStream(new FileOutputStream(tempFile, true));
+ 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();

- 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));
+ String device = null;

- String in = tempbr.readLine();
+ 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();

- while (in != null &&
!in.equals("")) {
-
tempout.writeBytes(in.replace("@@@cache@@@", "@@@"+cachetime+"@@@")+"\n");

- in =
tempbr.readLine();
- }
+ 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);

- 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(device);
+ System.out.println("======");
+ System.out.println();

- 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());
+ metadata = new Element("metadata", NMWG);
+ metadata.setAttribute("id", "metadata" + index);

- data = new
Element("data", NMWG);
-
data.setAttribute("id", "data" + index);
-
data.setAttribute("metadataIdRef", "metadata" + index);
-
-
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
-
-
store.addContent(data);
+ Element subject = new Element("subject", NMWG);
+ subject.setAttribute("id", "subject0");
+ subject.addContent(device);

- tempFile.delete();
- } 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());

+ metadata.addContent(subject);

- 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 { // Shouldn't happen
-
System.out.println("ERROR - Not a valid device.");
- }
- }
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
+ Element params = new Element("parameters", NMWG);
+ params.setAttribute("id", "metaParams0");

- System.out.println();
- System.out.println("That's all folks!");
- }
+ Element param;

- 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());
+ if (type.equalsIgnoreCase("1") ||
type.equalsIgnoreCase("2") || type.equalsIgnoreCase("4") ||
type.equalsIgnoreCase("5")) {

- BufferedReader br = new BufferedReader(new
FileReader(file));
- StringTokenizer tok = null;
+ 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!");
+ }

- BufferedReader in = new BufferedReader(
- new InputStreamReader(System.in));
+ 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();
+ 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 + ": ");
+ 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);

- String name = "";
- String command = "";
- String descr = "";
- String syntax = "";
- int index = 1;
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "cache");
+ param.setAttribute("value", "0");
+ params.addContent(param);

- 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(params);
+ } else if (type.equalsIgnoreCase("3") ||
type.equalsIgnoreCase("6")) {

- 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;
- }
- }
+ 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);

- DataOutputStream dos = new
DataOutputStream(new FileOutputStream(outFile, true));
+ } else {
+ System.out.print("An error that should be
possible occured!");
+ }

- 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();
- }
+ 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();
+ 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 + ": ");
+ 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();

- br.close();
- dos.close();
- }
- System.out.println("\nChoosen commands temporarily
saved to file...\n");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException ioe) {
- ioe.printStackTrace();
- }
+ if (input != null && !input.equals("")) {
+ param = new Element("parameter", NMWG);
+ param.setAttribute("name", "passphrase");
+ param.setAttribute("value",
PasswordEncryptor.encryptPassword(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);
+ }

- String input = "";
+ store.addContent(metadata);

- try {
- BufferedReader br = new BufferedReader(new
FileReader(inputfile));
+ System.out.println();

- input = br.readLine();

- String command = "";
- String realCommand = "";
- String minParamCount = "";
- String maxParamCount = "";
- String cache = "";
- String description = "";
- String syntax = "";
- String regExp = "";
+ 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();
+ }

- StringTokenizer tok;
+ if (input.equals("yes")) { // use predefined set

- 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);
- }
+ 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 (!cache.equalsIgnoreCase("---")) {
- param = new Element("parameter",
NMWG);
- param.setAttribute("name","caching");
- param.setAttribute("value",cache);
- params.addContent(param);
- }
+ File tempFile = File.createTempFile(device +
"minimum", ".tmp");

- if (!description.equalsIgnoreCase("---")) {
- param = new Element("parameter",
NMWG);
-
param.setAttribute("name","description");
-
param.setAttribute("value",description);
- params.addContent(param);
- }
+ DataOutputStream tempout = new DataOutputStream(new
FileOutputStream(tempFile, true));

- if (!syntax.equalsIgnoreCase("---")) {
- param = new Element("parameter",
NMWG);
- param.setAttribute("name","syntax");
- param.setAttribute("value",syntax);
- params.addContent(param);
- }
+ 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));

- 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(command);
-
- 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();
- }
+ 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 {
- ServicePropertiesConfigurator stitcher = new
ServicePropertiesConfigurator();
- stitcher.doStuff(args[0]);
- }
- } 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());
+
+ 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 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());
+
+ 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 { // Shouldn't happen
+ System.out.println("ERROR - Not a valid
device.");
+ }
+ }
+ }
+ }
+ } 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("\nChoosen 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(command);
+
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/WebserviceEngineAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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
()
@@ -42,462 +42,431 @@
*/
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 = 0;

- 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;
+ // ---------------------- constructors
+ public WebserviceEngineAdapter() throws PerfSONARException {

- // ---------------------- class-fields
+ try {

- private LoggerComponent logger = null;
+ this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";

- private MetadataConfiguration configuration = null;
+ this.logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().
+ getComponent(ComponentNames.LOGGER);

-
- // List of all supported devices, populated from the
service.properties
- // files
- private List devices = null;
-
- // ---------------------- constructors
-
- public WebserviceEngineAdapter() throws PerfSONARException {
-
- try {
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
-
- this.logger = (LoggerComponent)
- AuxiliaryComponentManager.
- getInstance().
- getComponent(ComponentNames.LOGGER);
-
this.configuration = new DbMetadataConfiguration();
configuration.initStorage();
-
+
devices =
configuration.getProperties(MetadataConfiguration.DEVICE_NAMES);
-
- registerServiceWithLS();

- } catch (PerfSONARException e) {
+ registerServiceWithLS();

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ } catch (PerfSONARException e) {

- }
+
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.");

- }// WebserviceEngineAdapter
+ }

- // ---------------------- Methods from service engine interface
+ }// WebserviceEngineAdapter

- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {

- return this.serviceEngineType;
+ return this.serviceEngineType;

- }
+ }

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- logger.info("[WebserviceEngineAdapter] Webservice takeAction
call received");
-
- logger.info("COUNT: " + count++);
+ logger.info("[WebserviceEngineAdapter] Webservice takeAction call
received");

- Metadata[] requestMetadata = request.getMetadataArray();
- Data[] requestData = request.getDataArray();
-
- if (actionType.equalsIgnoreCase(ActionType.GET_KEY)) {
+ logger.info("COUNT: " + count++);

- return createServiceCapabilitiesResponse(request);
+ Metadata[] requestMetadata = request.getMetadataArray();
+ Data[] requestData = request.getDataArray();

- }
+ if (actionType.equalsIgnoreCase(ActionType.GET_KEY)) {

- // Find the correct handler for the device requested
- else {
+ return createServiceCapabilitiesResponse(request);

- logger.debug("NUMBER OF BLOCKs: " +
requestMetadata.length);
+ } // Find the correct handler for the device requested
+ else {

- messages = new Message[requestMetadata.length];
- RequestMonitor requestMonitor = new RequestMonitor(
- requestMetadata.length);
+ logger.debug("NUMBER OF BLOCKs: " + requestMetadata.length);

- for (int i = 0; i < requestMetadata.length; i++) {
- Subject subjectTemp =
requestMetadata[i].getSubject();
- boolean deviceElementOK = true;
- String value = "";
+ messages = new Message[requestMetadata.length];
+ RequestMonitor requestMonitor = new RequestMonitor(
+ requestMetadata.length);

- try {
- EndPoint endpoint = (EndPoint)
subjectTemp.getChildArray()[0];
- value = endpoint.getValue();
- } catch (Exception e) {
- deviceElementOK = false;
- }
+ for (int i = 0; i < requestMetadata.length; i++) {
+ Subject subjectTemp = requestMetadata[i].getSubject();
+ boolean deviceElementOK = true;
+ String value = "";

- if (deviceElementOK &&
devices.contains(value)) {
+ try {
+ EndPoint endpoint = (EndPoint)
subjectTemp.getChildArray()[0];
+ value = endpoint.getValue();
+ } catch (Exception e) {
+ deviceElementOK = false;
+ }

- Message message = new Message();
-
message.setMetadata(requestMetadata[i]);
- String metadataIdRef =
requestMetadata[i].getId();
+ if (deviceElementOK && devices.contains(value)) {

- for (int j = 0; j <
requestData.length; j++)
- if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
-
metadataIdRef))
-
message.setData(requestData[j]);
+ Message message = new Message();
+ message.setMetadata(requestMetadata[i]);
+ String metadataIdRef = requestMetadata[i].getId();

- String serviceEngineString =
configuration
-
.getProperty(value,"class_name");
+ for (int j = 0; j < requestData.length; j++) {
+ if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
+ metadataIdRef)) {
+ message.setData(requestData[j]);
+ }
+ }

- RequestExecutingThread
requestExecutingThread = new RequestExecutingThread(
- i, actionType,
serviceEngineString, message,
- requestMetadata[i],
requestMonitor);
+ String serviceEngineString =
configuration.getProperty(value, "class_name");

- requestExecutingThread.start();
+ RequestExecutingThread requestExecutingThread = new
RequestExecutingThread(
+ i, actionType, serviceEngineString, message,
+ requestMetadata[i], requestMonitor);

- } else {
+ requestExecutingThread.start();

- messages[i] = new Message();
-
messages[i].setMetadata(requestMetadata[i]);
- String metadataIdRef =
requestMetadata[i].getId();
+ } else {

- for (int j = 0; j <
requestData.length; j++)
- if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
-
metadataIdRef))
-
messages[i].setData(requestData[j]);
+ messages[i] = new Message();
+ messages[i].setMetadata(requestMetadata[i]);
+ String metadataIdRef = requestMetadata[i].getId();

- Metadata resultCodeMetadata = new
Metadata();
-
resultCodeMetadata.setId("resultCodeMeta_"
- +
requestMetadata[i].getId());
+ for (int j = 0; j < requestData.length; j++) {
+ if
(requestData[j].getMetadataIdRef().equalsIgnoreCase(
+ metadataIdRef)) {
+ messages[i].setData(requestData[j]);
+ }
+ }

- Subject resultCodeSubject = new
Subject();
-
resultCodeSubject.setId("resultCodeSubj_"
- +
requestMetadata[i].getId());
-
resultCodeSubject.setMetadataIdRef(requestMetadata[i]
- .getId());
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
requestMetadata[i].getId());

- EventType resultCodeEventType = new
EventType();
-
resultCodeEventType.setId("resultCodeEventType_"
- +
requestMetadata[i].getId());
- resultCodeEventType
-
.setEventType("error.mp.sshtelnet.device");
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
requestMetadata[i].getId());
+
resultCodeSubject.setMetadataIdRef(requestMetadata[i].getId());

-
resultCodeMetadata.addChild(resultCodeSubject);
-
resultCodeMetadata.addChild(resultCodeEventType);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
requestMetadata[i].getId());
+
resultCodeEventType.setEventType("error.mp.sshtelnet.device");

- Data resultCodeData = new Data();
- resultCodeData.setId("resultCodeData_"
- +
requestMetadata[i].getId());
-
resultCodeData.setMetadataIdRef("resultCodeMeta_"
- +
requestMetadata[i].getId());
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);

- 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");
- }
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" +
requestMetadata[i].getId());
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
requestMetadata[i].getId());

-
resultCodeData.addChild(resultCodeDatum);
+ 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");
+ }

-
messages[i].setMetadata(resultCodeMetadata);
- messages[i].setData(resultCodeData);
+ resultCodeData.addChild(resultCodeDatum);

- requestMonitor.setCompleted(i, null);
+ messages[i].setMetadata(resultCodeMetadata);
+ messages[i].setData(resultCodeData);

- }
- }
+ requestMonitor.setCompleted(i, null);

- while (!requestMonitor.isCompleted()) {
- try {
- Toolkit toolkit =
Toolkit.getDefaultToolkit();
- toolkit.beep();
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
+ }
+ }

- Message[] resultMessages =
requestMonitor.getResultMessages();
+ while (!requestMonitor.isCompleted()) {
+ try {
+ Toolkit toolkit = Toolkit.getDefaultToolkit();
+ toolkit.beep();
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+
logger.error("[WEBSERVICEENGINEADAPTER][TakeAction]"+e.getStackTrace().toString());
+ }
+ }

- for (int i = 0; i < messages.length; i++) {
- if (messages[i] == null)
- messages[i] = resultMessages[i];
- }
+ Message[] resultMessages = requestMonitor.getResultMessages();

- Message returnMessage = new Message();
- for (int i = 0; i < messages.length; i++) {
+ for (int i = 0; i < messages.length; i++) {
+ if (messages[i] == null) {
+ messages[i] = resultMessages[i];
+ }
+ }

- for (int j = 0; j <
messages[i].getMetadataArray().length; j++) {
- returnMessage
-
.setMetadata(messages[i].getMetadataArray()[j]);
- }
+ Message returnMessage = new Message();
+ for (int i = 0; i < messages.length; i++) {

- for (int j = 0; j <
messages[i].getDataArray().length; j++) {
-
returnMessage.setData(messages[i].getDataArray()[j]);
- }
+ 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]);
+ }

- return returnMessage;
+ }

- }
+ return returnMessage;

- // return new ServiceEngineResponse();
+ }

- }
+ // return new ServiceEngineResponse();

- private Message createServiceCapabilitiesResponse(Message request) {
+ }

- Message response = new Message();
- response.setId(request.getId());
- response.setType("MetadataKeyResponse");
+ private Message createServiceCapabilitiesResponse(Message request) {

- Data[] respData;
- Metadata[] respMetaData;
+ Message response = new Message();
+ response.setId(request.getId());
+ response.setType("MetadataKeyResponse");

- Iterator it = devices.iterator();
- String token = null;
- int tokencounter = 0;
- String innerToken = null;
- StringTokenizer tokenizer = null;
+ Data[] respData;
+ Metadata[] respMetaData;

- respMetaData = new Metadata[devices.size()];
- respData = new Data[devices.size()];
+ Iterator it = devices.iterator();
+ String token = null;
+ int tokencounter = 0;
+ String innerToken = null;
+ StringTokenizer tokenizer = null;

- Subject subject = null;
- EventType eventType = null;
- Datum datum = null;
+ respMetaData = new Metadata[devices.size()];
+ respData = new Data[devices.size()];

- while (it.hasNext()) {
+ Subject subject = null;
+ EventType eventType = null;
+ Datum datum = null;

- token = (String) it.next();
+ while (it.hasNext()) {

- respMetaData[tokencounter] = new Metadata();
- respMetaData[tokencounter].setId("metadata" +
tokencounter);
+ token = (String) it.next();

- subject = new Subject();
- subject.setId("subject" + tokencounter);
- subject.setSubject(token);
+ respMetaData[tokencounter] = new Metadata();
+ respMetaData[tokencounter].setId("metadata" + tokencounter);

- Parameters metaParams = new Parameters();
- metaParams.setId("metaParams" + tokencounter);
+ subject = new Subject();
+ subject.setId("subject" + tokencounter);
+ subject.setSubject(token);

- Parameter metaparam = new Parameter();
- metaparam.setParameterName("url");
- try {
- metaparam.setParameterValue(configuration
- .getProperty(token, "url"));
- } catch (PerfSONARException e1) {
- e1.printStackTrace();
- }
+ Parameters metaParams = new Parameters();
+ metaParams.setId("metaParams" + tokencounter);

- metaParams.addChild(metaparam);
+ Parameter metaparam = new Parameter();
+ metaparam.setParameterName("url");
+ try {
+ metaparam.setParameterValue(configuration.getProperty(token,
"url"));
+ } catch (PerfSONARException e1) {
+
logger.error("[WEBSERVICEENGINEADAPTER][CreateServiceCapabilitiesResponse]"+e1.getStackTrace().toString());
+ }

- respMetaData[tokencounter].addChild(subject);
- respMetaData[tokencounter].addChild(metaParams);
+ metaParams.addChild(metaparam);

- try {
+ respMetaData[tokencounter].addChild(subject);
+ respMetaData[tokencounter].addChild(metaParams);

- //re-write this to ArrayList
-
- Iterator commands =
configuration.getProperties(token,"commands").iterator();
- respData[tokencounter] = new Data();
- respData[tokencounter].setId("data" +
tokencounter);
- respData[tokencounter]
-
.setMetadataIdRef(respMetaData[tokencounter].getId());
+ try {

- while (commands.hasNext()) {
+ //re-write this to ArrayList

- innerToken = (String) commands.next();
+ Iterator commands = configuration.getProperties(token,
"commands").iterator();
+ respData[tokencounter] = new Data();
+ respData[tokencounter].setId("data" + tokencounter);
+
respData[tokencounter].setMetadataIdRef(respMetaData[tokencounter].getId());

- datum = new Datum();
+ while (commands.hasNext()) {

- eventType = new EventType();
- eventType.addText(innerToken);
- // System.out.println(innerToken);
+ innerToken = (String) commands.next();

- Parameters params = new Parameters();
- params.setId("params" + tokencounter);
+ datum = new Datum();

- Parameter param1 = new Parameter();
- try {
- param1.setId("param1-" +
tokencounter);
-
param1.setParameterName("description");
-
param1.setParameterValue(configuration
-
.getProperty(token, innerToken, "description"));
- } catch (PerfSONARException e) {
- }
+ eventType = new EventType();
+ eventType.addText(innerToken);
+ logger.debug(innerToken);

- Parameter param2 = new Parameter();
- try {
- param2.setId("param2-" +
tokencounter);
-
param2.setParameterName("syntax");
- param2
-
.setParameterValue(configuration
-
.getProperty(token, innerToken, "syntax"));
- } catch (PerfSONARException e) {
- }
+ Parameters params = new Parameters();
+ params.setId("params" + tokencounter);

- Parameter param3 = new Parameter();
- try {
- param3.setId("param3-" +
tokencounter);
-
param3.setParameterName("command");
-
param3.setParameterValue(configuration
-
.getProperty(token, innerToken, "command"));
- } catch (PerfSONARException e) {
- }
+ 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().toString());
+ }

- params.addChild(param1);
- params.addChild(param2);
- params.addChild(param3);
+ 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().toString());
+ }

- datum.addChild(eventType);
- datum.addChild(params);
+ 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().toString());
+ }

-
respData[tokencounter].addChild(datum);
+ params.addChild(param1);
+ params.addChild(param2);
+ params.addChild(param3);

- // Result Code stuff
- Metadata resultCodeMetadata = new
Metadata();
-
resultCodeMetadata.setId("resultCodeMeta_" + tokencounter);
+ datum.addChild(eventType);
+ datum.addChild(params);

- Subject resultCodeSubject = new
Subject();
-
resultCodeSubject.setId("resultCodeSubj_" + tokencounter);
-
resultCodeSubject.setMetadataIdRef("metadata"
- + tokencounter);
+ respData[tokencounter].addChild(datum);

- EventType resultCodeEventType = new
EventType();
-
resultCodeEventType.setId("resultCodeEventType_"
- + tokencounter);
-
resultCodeEventType.setEventType("success.mp.sshtelnet");
+ // Result Code stuff
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" +
tokencounter);

-
resultCodeMetadata.addChild(resultCodeSubject);
-
resultCodeMetadata.addChild(resultCodeEventType);
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" +
tokencounter);
+ resultCodeSubject.setMetadataIdRef("metadata" +
tokencounter);

- Data resultCodeData = new Data();
-
resultCodeData.setId("resultCodeData_" + tokencounter);
-
resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + tokencounter);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
tokencounter);
+ resultCodeEventType.setEventType("success.mp.sshtelnet");

- Datum resultCodeDatum = new Datum();
-
resultCodeDatum.setId("resultCodeDatum_" + tokencounter);
- resultCodeDatum
-
.setValue("Successfully executed MetaDataKeyRequest");
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);

-
resultCodeData.addChild(resultCodeDatum);
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" + tokencounter);
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
tokencounter);

-
response.setMetadata(resultCodeMetadata);
- response.setData(resultCodeData);
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" + tokencounter);
+ resultCodeDatum.setValue("Successfully executed
MetaDataKeyRequest");

- }
+ resultCodeData.addChild(resultCodeDatum);

- } catch (PerfSONARException e) {
+ response.setMetadata(resultCodeMetadata);
+ response.setData(resultCodeData);

- // Result Code stuff
- Metadata resultCodeMetadata = new Metadata();
- resultCodeMetadata.setId("resultCodeMeta_" +
tokencounter);
+ }

- Subject resultCodeSubject = new Subject();
- resultCodeSubject.setId("resultCodeSubj_" +
tokencounter);
- resultCodeSubject.setMetadataIdRef("metadata"
+ tokencounter);
+ } catch (PerfSONARException e) {

- EventType resultCodeEventType = new
EventType();
- resultCodeEventType
- .setId("resultCodeEventType_"
+ tokencounter);
-
resultCodeEventType.setEventType("success.mp.sshtelnet");
+ // Result Code stuff
+ Metadata resultCodeMetadata = new Metadata();
+ resultCodeMetadata.setId("resultCodeMeta_" + tokencounter);

-
resultCodeMetadata.addChild(resultCodeSubject);
-
resultCodeMetadata.addChild(resultCodeEventType);
+ Subject resultCodeSubject = new Subject();
+ resultCodeSubject.setId("resultCodeSubj_" + tokencounter);
+ resultCodeSubject.setMetadataIdRef("metadata" +
tokencounter);

- Data resultCodeData = new Data();
- resultCodeData.setId("resultCodeData_" +
tokencounter);
-
resultCodeData.setMetadataIdRef("resultCodeMeta_"
- + tokencounter);
+ EventType resultCodeEventType = new EventType();
+ resultCodeEventType.setId("resultCodeEventType_" +
tokencounter);
+ resultCodeEventType.setEventType("success.mp.sshtelnet");

- Datum resultCodeDatum = new Datum();
- resultCodeDatum.setId("resultCodeDatum_" +
tokencounter);
- resultCodeDatum
- .setValue("Successfully
executed MetaDataKeyRequest");
+ resultCodeMetadata.addChild(resultCodeSubject);
+ resultCodeMetadata.addChild(resultCodeEventType);

- resultCodeData.addChild(resultCodeDatum);
+ Data resultCodeData = new Data();
+ resultCodeData.setId("resultCodeData_" + tokencounter);
+ resultCodeData.setMetadataIdRef("resultCodeMeta_" +
tokencounter);

- response.setMetadata(resultCodeMetadata);
- response.setData(resultCodeData);
+ Datum resultCodeDatum = new Datum();
+ resultCodeDatum.setId("resultCodeDatum_" + tokencounter);
+ resultCodeDatum.setValue("Successfully executed
MetaDataKeyRequest");

- }
+ resultCodeData.addChild(resultCodeDatum);

- response.setMetadata(respMetaData[tokencounter]);
- response.setData(respData[tokencounter]);
- tokencounter++;
+ response.setMetadata(resultCodeMetadata);
+ response.setData(resultCodeData);

- }
+ }

- return response;
+ response.setMetadata(respMetaData[tokencounter]);
+ response.setData(respData[tokencounter]);
+ tokencounter++;

- }
+ }

- 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(); }
- */
- }
+ return response;

- // 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) {
- }
- }
- }
- }
+ 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(); }
+ */
+ }

- 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(); }
- */
+ // THREAD TESTING PURPOSES
+ public class SimpleThread extends Thread {

- try {
- WebserviceEngineAdapter adapter = new
WebserviceEngineAdapter();
- } catch (PerfSONARException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ 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) {
+ //e.printStackTrace();
+ }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/CommandInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -9,7 +9,7 @@

/**
* Implementation class that supports querying the device for
- * ip information
+ * information
*
* TODO::Correct error classes TODO::Parse output ??
*

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/engine/commands/ParameterChecker.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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,6 +10,7 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

+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;
@@ -21,81 +22,78 @@
*
*/
public class ParameterChecker implements ParameterCheckerInterface {
-
- private MetadataConfiguration properties;

- /**
- * 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 {
+ /**
+ * 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) {
+
+ 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 {
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();
- }
+ String regularExpressions = properties.getProperty(subject,
eventTypeString, "regex");
+ //System.out.println("Regular Expressions for command " +
eventTypeString + ": " + regularExpressions);
+ StringTokenizer disjunct = new
StringTokenizer(regularExpressions, "#");

- return ok;
- }
-
-
- /**
- * Test-purposes
- *
- * @param argv
- */
- public static void main(String[] argv) {
+ while (disjunct.hasMoreTokens() && !ok) {

- ParameterChecker checker = new ParameterChecker();
- System.out.println(checker.checkParam("juniper1",
"BGP_PEERING_STATUS",
- "157.193.214.0/24"));
- }
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/IpAdapterInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoIpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,623 +44,581 @@
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// 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"));

- }// getCommand
+ manager = new TelnetManager(url, port, false);
+ ((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(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(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ public String getPrompt() {

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(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 ...");
+ }

- Iterator commands = 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);

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- token = (String) commands.next();
- 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(subject,
token, "command"));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- String tempResult = temp
- .substring((ipCommand.getCommand() + " " +
ipCommand
-
.getParameterString()).length());
+ CiscoIpAdapter adapter = new CiscoIpAdapter();

- 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"));

- return t2.replace("" + prompt, "---END---");
+ manager = new TelnetManager(url, port, false);

- }
+ } catch (NumberFormatException e1) {

- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOIPADAPTER][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("[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.debug("[CiscoStatusAdapter] TelnetManager created: " + url +
" " + port);

- logger.info("[CiscoIpAdapter] 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("[CISCOIPADAPTER][TakeAction]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- EventType eventType = metadata[0].getEventType();
- String eventTypeString = eventType.getEventType();
+ }

- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ logger.debug("[CiscoStatusAdapter] Prompt set in TelnetManager: " +
prompt);

- CiscoIpAdapter adapter = new CiscoIpAdapter();
- //adapter.connect(subject);
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);

- // REPLACED
+ //

- availableSpecificCommands = new ArrayList();
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);

- try {
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();

- url = properties.getProperty(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(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)) {
+ ipCommand.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 (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {

- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve url");
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- }
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();

- logger.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ 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();

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(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 connection
details");
+ }

- }
+ }

- logger.debug("[CiscoStatusAdapter] 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(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();
-
- }
+ adapter.connect(subject);
+ temp = adapter.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("[CiscoIpAdapter] Command executed succesfully");
+ }

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoIpAdapter] Command executed succesfully");

- logger.info("[CiscoIpAdapter] Constructing response message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[CiscoIpAdapter] Constructing response message");

- 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]);
+ Message response = new Message();

- // System.err.println(respMetaData);
- // System.err.println(respData);
+ 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]);

- // response.setSonarMetadata(request.getSonarMetadata());
- // response.setSonarData(new Data[] { data });
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");

- logger.info("[CiscoIpAdapter] takeAction finished");
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });

- return response;
- // return new ServiceEngineResponse();
+ logger.info("[CiscoIpAdapter] takeAction finished");

- }
+ return response;
+ // return new ServiceEngineResponse();

- // ---------------------- Stand-alond Test Method
+ }

- public static void main(String[] args) {
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- try {
- CiscoIpAdapter adapter = new CiscoIpAdapter();
+ try {
+ CiscoIpAdapter adapter = new CiscoIpAdapter();

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("cisco1");
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("cisco1");

- adapter.connect("cisco1");
+ adapter.connect("cisco1");

- 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);
+ ipCommand = adapter.getCommand("IP_ROUTE");
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoKeyIpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -101,7 +101,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.");

@@ -188,7 +188,7 @@

if (manager != null) {

- System.out.println("Executing command");
+ logger.debug("Executing command");
String temp2 =
manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());

@@ -249,8 +249,7 @@

} 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");
@@ -326,12 +325,14 @@

.getProperty(subject, token, "minParamCount"));

command.setMinParamCount(minParamCount);
} catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYIPADAPTER][ConfigureCommands]"+e1.getStackTrace().toString());
}
try {
int maxParamCount =
Integer.parseInt(properties

.getProperty(subject, token, "maxParamCount"));

command.setMaxParamCount(maxParamCount);
} catch (PerfSONARException e1) {
+
logger.error("[CISCOKEYIPADAPTER][ConfigureCommands]"+e1.getStackTrace().toString());
}

command.setDeviceName(subject);
@@ -343,7 +344,7 @@

} catch (PerfSONARException e) {

- e.printStackTrace();
+
logger.error("[CISCOKEYIPADAPTER][ConfigureCommands]"+e.getStackTrace().toString());
throw new
PerfSONARException("error.mp.sshtelnet.configuration",
"Unable to retrieve commands");

@@ -377,9 +378,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);

@@ -420,7 +421,7 @@
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();
@@ -453,14 +454,14 @@

} 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");

@@ -484,7 +485,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)) {
@@ -631,15 +632,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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/CiscoSshIpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,591 +44,548 @@
*/
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 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 MetadataConfiguration 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");

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ 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"));

- }
+ //System.out.println(username);
+ //System.out.println(password);

- }// while
+ manager = new SshManager(url, username, password, false);

- logger.error("[CiscoSshIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[CiscoSshIpAdapter] Trying to connect");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");

- logger.debug("[CiscoSshIpAdapter] executeCommand called");
+ logger.info("[CiscoSshIpAdapter Login");

- if (manager != null) {
+ } catch (Exception e) {

- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ 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");

- }// if
+ }

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshIpAdapter] 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.info("[CiscoSshIpAdapter] Connect called");
+ public void setPort(int port) {

- try {
+ this.port = port;

- 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("[CiscoSshIpAdapter]
Error in configuration");
-
logger.error(e.getStackTrace().toString());
- throw e;
- }
- caching =
Integer.parseInt(properties.getProperty(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("[CiscoSshIpAdapter] Trying to connect");
+ this.prompt = prompt;

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }

- logger.info("[CiscoSshIpAdapter Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return url;

- 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) {

- }// 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("[CiscoSshIpAdapter] 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 {
+ 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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[CISCOSSHIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[CiscoSshIpAdapter] 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 {
+ String tempResult = temp;
+// .substring((ipCommand.getCommand() + " " +
ipCommand
+//
.getParameterString()).length());

- logger.debug("[CiscoSshIpAdapter] Configuring available
operations ...");
+ String t1 = tempResult.replaceAll("\\n", "");
+ String t2 = t1.replaceAll("\\r", "@@@");

- Iterator commands = 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, ' ');
+ }
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ t2 = resultBuffer.toString();

- token = (String) commands.next();
- if (token.contains("IP")) {
+ return t2.replace("" + prompt, "---END---");

- IpCommand command = new
IpCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoSshIpAdapter] Webservice takeAction call
received");

- logger.debug("[CiscoSshIpAdapter] 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, IpCommandInterface
ipCommand) {
+ logger.debug("SUBJECTSTRING: " + subject);

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();

- 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"));

- return t2.replace("" + prompt, "---END---");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- }
+ } catch (NumberFormatException e1) {

- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOSSHIPADAPTER][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("[CISCOSSHIPADAPTER][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("[CiscoSshIpAdapter] 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);

- CiscoSshIpAdapter adapter = new CiscoSshIpAdapter();
- //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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(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);
+ adapter.connect(subject);
+ temp = adapter.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();
-
- }
+ adapter.connect(subject);
+ temp = adapter.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.");

- //System.out.println("[CiscoSshIpAdapter] Command executed
succesfully");
- logger.info("[CiscoSshIpAdapter] Command executed
succesfully");
- //System.out.println(valid);
+ }

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipCommand));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoSshIpAdapter] Command executed succesfully");

- //System.out.println("[CiscoSshIpAdapter] Constructing
response message");
- logger.info("[CiscoSshIpAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[CiscoSshIpAdapter] 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("[CiscoSshIpAdapter] 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("[CiscoSshIpAdapter] 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 {
- 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperIpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,620 +44,578 @@
*/
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 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 JuniperIpAdapter() 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("[JUNIPERIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");

- private MetadataConfiguration properties = null;
-
- // ---------------------- caching attributes
+ }

- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperIpAdapter] Constructor finished");

- // ---------------------- constructors
+ }// JuniperIpAdapter

- public JuniperIpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {

- try {
+ logger.debug("[JuniperIpAdapter] getAvailableSpecificCommands
called");

- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[JuniperIpAdapter] 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("[JuniperIpAdapter] addAvailableSpecificCommand
called");

- }
+ availableSpecificCommands.add(command);

- logger.debug("[JuniperIpAdapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {

- }// JuniperIpAdapter
+ logger.debug("[JuniperIpAdapter] 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("[JuniperIpAdapter] getAvailableSpecificCommands
called");
+ command = (IpCommand) it.next();

- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {

- }// getAvailableSpecificCommands
+ logger.debug("[JuniperIpAdapter] Command found");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }

- logger.debug("[JuniperIpAdapter] setAvailableSpecificCommand
called");
+ }// while

- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperIpAdapter] 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("[JuniperIpAdapter] executeCommand called");

- logger.debug("[JuniperIpAdapter] 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);
+ command.setTimestamp(System.currentTimeMillis());

- logger.debug("[JuniperIpAdapter] getCommand called");
+ }// if

- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperIpAdapter] executeCommand finished");
+ return command;

- while (it.hasNext()) {
+ }// executeCommand
+ public void connect() {
+ }

- command = (IpCommand) it.next();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ logger.debug("[JuniperIpAdapter] Connect called");

- logger.debug("[JuniperIpAdapter] 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");
+ 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"));

- logger.error("[JuniperIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new TelnetManager(url, port, false);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));

- }// getCommand
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ logger.debug("[JuniperIpAdapter] Trying to connect");

- logger.debug("[JuniperIpAdapter] executeCommand called");
+ manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");

- if (manager != null) {
+ logger.debug("[JuniperIpv6Adapter Login");

- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
- System.err.println("temp2: " + temp2);
+ } catch (Exception e) {

- manager.disconnect();
+ 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");

- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }

- }// if
+ }// connect

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperIpAdapter] 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.debug("[JuniperIpAdapter] Connect called");
+ this.port = port;

- try {
+ }

- if (manager == null) {
+ public String getPrompt() {

- 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"));
+ return prompt;

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject,
"prompt"));
+ }

- }
+ public void setPrompt(String prompt) {

- logger.debug("[JuniperIpAdapter] Trying to connect");
+ this.prompt = prompt;

- manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }

- logger.debug("[JuniperIpv6Adapter Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return url;

- 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) {

- }// 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("[JuniperIpAdapter] 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 {
+ 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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[JUNIPERIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- 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"));

- }
+ logger.debug("[JuniperIpAdapter] 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("[JuniperIpAdapter] Configuring available
operations ...");
+ while (temp.indexOf("---(more") > 0) {

- Iterator commands = null;
- String token = null;
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- try {
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ String tempResult = temp.substring((ipCommand.getCommand() + " " +
ipCommand.getParameterString()).length());

- token = (String) commands.next();
- if (token.contains("IP_")) {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- IpCommand command = new
IpCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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() {

- //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 this.serviceEngineType;

- logger.debug("[JuniperIpAdapter] 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("[JuniperIpAdapter] 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();

- 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"));

- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new TelnetManager(url, port, false);

- 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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(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(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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperKeyIpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,613 +44,574 @@
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// 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"));

- }// while
+ manager = new SshKeyManager(url, username, keyUrl, false);

- logger.error("[JuniperKeyIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[JuniperKeyIpAdapter] Trying to connect");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface executeCommand(IpCommandInterface command) {
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[JuniperKeyIpAdapter] Login");

- logger.debug("[JuniperKeyIpAdapter] executeCommand called");
+ } catch (Exception e) {

- if (manager != null) {
+ 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");

- System.out.println("Executing command");
- 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("[JuniperStatusAdapter] 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.info("[JuniperKeyIpAdapter] Connect called");
+ }

- try {
+ public String getPrompt() {

- if (manager == null) {
+ return prompt;

- 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"));
+ }

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ public void setPrompt(String prompt) {

- }
+ 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");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[JuniperKeyIpAdapter] 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 {
+ 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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[JUNIPERKEYIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- return url;
+ }

- }
+ logger.debug("[JuniperKeyIpAdapter] 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("[JuniperKeyIpAdapter] Configuring
available operations ...");
+ while (temp.indexOf("---(more") > -1) {

- Iterator commands = null;
- String token = null;
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- try {
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- token = (String) commands.next();
- 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(subject,
token, "command"));
- try {
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[JuniperKeyIpAdapter] 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("[JuniperKeyIpAdapter] 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();

- }
+ 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"));

- t2 = resultBuffer.toString();
+ manager = new SshKeyManager(url, username, keyUrl, false);

- 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(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"));
+ } 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);
+ adapter.connect(subject);
+ temp = adapter.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 {
+ 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("[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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/adapters/JuniperSshIpAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,601 +44,563 @@
*/
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 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 = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);

- 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("[JUNIPERSSHIPADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshYE.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");

- private MetadataConfiguration properties = null;
+ }

- // ---------------------- caching attributes
+ logger.debug("[JuniperSshIpAdapter] Constructor started");

- private static List cachedResults = new ArrayList();
+ logger.debug("[JuniperSshIpAdapter] Constructor finished");

- // ---------------------- constructors
+ }// JuniperSshIpAdapter

- public JuniperSshIpAdapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {

- try {
+ logger.debug("[JuniperSshIpAdapter] getAvailableSpecificCommands
called");

- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperSshIpAdapter] 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.sshYE.configuration",
- "Failed to obtain reference to the properties and/or
logger instances.");
+ logger.debug("[JuniperSshIpAdapter] addAvailableSpecificCommand
called");

- }
+ availableSpecificCommands.add(command);

- logger.debug("[JuniperSshIpAdapter] Constructor started");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public IpCommandInterface getCommand(String description)
+ throws PerfSONARException {

- logger.debug("[JuniperSshIpAdapter] Constructor finished");
+ logger.debug("[JuniperSshIpAdapter] getCommand called");

- }// JuniperSshIpAdapter
+ 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("[JuniperSshIpAdapter]
getAvailableSpecificCommands called");
+ if (command.getDescription().equalsIgnoreCase(description)) {

- return availableSpecificCommands;
+ logger.debug("[JuniperSshIpAdapter] Command found");
+ return command;

- }// getAvailableSpecificCommands
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while

- logger.debug("[JuniperSshIpAdapter]
setAvailableSpecificCommand called");
+ logger.error("[JuniperSshIpAdapter] 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("[JuniperSshIpAdapter] executeCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(IpCommandInterface command) {
+ if (manager != null) {

- logger.debug("[JuniperSshIpAdapter]
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("[JuniperSshIpAdapter] executeCommand finished");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public IpCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// executeCommand
+ public void connect() {
+ }

- logger.debug("[JuniperSshIpAdapter] getCommand called");
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- IpCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("[JuniperSshIpAdapter] Connect called");

- while (it.hasNext()) {
+ try {

- command = (IpCommand) 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");
+ 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"));

- logger.debug("[JuniperSshIpAdapter] Command
found");
- return command;
+ //System.out.println(username);
+ //System.out.println(password);

- }
+ manager = new SshManager(url, username, password, false);

- }// while
+ }

- logger.error("[JuniperSshIpAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ logger.info("[JuniperSshIpAdapter] 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("[JuniperSshIpAdapter Login");

- logger.debug("[JuniperSshIpAdapter] executeCommand called");
+ } catch (Exception e) {

- if (manager != null) {
+ 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");

- 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("[JuniperSshIpAdapter] 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("[JuniperSshIpAdapter] Connect called");
+ this.port = port;

- try {
+ }

- if (manager == null) {
+ public String getPrompt() {

- 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"));
+ 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("[JuniperSshIpAdapter] Trying to
connect");
+ }

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ public String getUrl() {

- logger.info("[JuniperSshIpAdapter Login");
+ return url;

- } catch (Exception e) {
+ }

- 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");
+ 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("[JuniperSshIpAdapter] 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("[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());
+ }

- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- return prompt;
+ }

- }
+ }

- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {

- this.prompt = prompt;
+ logger.error("[JUNIPERSSHIPADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- }
+ }

- public String getUrl() {
+ logger.debug("[JuniperSshIpAdapter] 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) {
+ 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("[JuniperSshIpAdapter] Configuring available
operations ...");
+ }

- Iterator commands = 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);

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- token = (String) commands.next();
- 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(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "maxParamCount"));
-
command.setMaxParamCount(maxParamCount);
- } catch (PerfSONARException e1) {
- }
+ t2 = resultBuffer.toString();

- 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("[JuniperSshIpAdapter] Available operations
configured");
+ logger.info("[JuniperSshIpAdapter] 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- while (temp.indexOf("---(more") > -1) {
+ JuniperSshIpAdapter adapter = new JuniperSshIpAdapter();

- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ // REPLACED

- }
+ 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");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- 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("[JUNIPERSSHIPADAPTER][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("[JUNIPERSSHIPADAPTER][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] SshManager 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);

- }
+ //

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ IpCommandInterface ipCommand = this.getCommand(eventTypeString);

- logger.info("[JuniperSshIpAdapter] 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)) {
+ ipCommand.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 (ipCommand.getParameters().size() >=
ipCommand.getMinParamCount() && ipCommand.getParameters().size() <=
ipCommand.getMaxParamCount() && valid) {

- JuniperSshIpAdapter adapter = new JuniperSshIpAdapter();
- //adapter.connect(subject);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- // REPLACED
+ 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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {

- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), 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");
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipCommand).getResult();

- }
+ }

- logger.debug("[CiscoStatusAdapter] SshManager 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 (ipCommand.getMinParamCount() == 0) {

- //
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- IpCommandInterface ipCommand =
this.getCommand(eventTypeString);
+ IpCommandInterface cachedCommand = (IpCommandInterface)
it.next();

- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
&& cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.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)) {
- ipCommand.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 (ipCommand.getParameters().size() >= ipCommand
- .getMinParamCount()
- && ipCommand.getParameters().size()
<= ipCommand
- .getMaxParamCount() && valid) {
+ }

- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
+ if (temp.equalsIgnoreCase("")) {

- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipCommand).getResult();

- 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 {

- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ 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();
+ }

- }
+ logger.info("[JuniperSshIpAdapter] Command executed succesfully");

- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- if (temp.equalsIgnoreCase("")) {
+ logger.info("[JuniperSshIpAdapter] Constructing response message");

- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
+ 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]);

- }
- 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("[JuniperSshIpAdapter] takeAction finished");

- } else if (ipCommand.getMinParamCount() == 0) {
+ return response;

- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
+ }

- IpCommandInterface cachedCommand =
(IpCommandInterface)it.next();
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- if
(cachedCommand.getCommand().equalsIgnoreCase(ipCommand.getCommand())
- &&
cachedCommand.getParameterString().equalsIgnoreCase(ipCommand.getParameterString())
- &&
cachedCommand.getDeviceName().equalsIgnoreCase(ipCommand.getDeviceName())
- &&
cachedCommand.getTimestamp()+(caching*1000) > System.currentTimeMillis()) {
+ try {
+ JuniperSshIpAdapter adapter = new JuniperSshIpAdapter();

- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("juniper2");

- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ adapter.connect("juniper2");

- logger.info("CACHED RESULT REMOVED");
- it.remove();
+ IpCommandInterface ipCommand;

- }
+ try {

- }
+ ipCommand = adapter.getCommand("IP");
+ String temp = adapter.executeCommand(ipCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);

- if (temp.equalsIgnoreCase("")) {
+ } catch (PerfSONARException e) {

- adapter.connect(subject);
- temp =
adapter.executeCommand(ipCommand).getResult();
+ //e.printStackTrace();

- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- } 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] Constructing response
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]);
-
- logger.info("[JuniperSshIpAdapter] takeAction finished");
-
- return response;
-
- }
-
- // ---------------------- Stand-alond Test Method
-
- public static void main(String[] args) {
-
- 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");
-
- adapter.connect("juniper2");
-
- IpCommandInterface ipCommand;
-
- try {
-
- 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) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommand.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ip/commands/IpCommandInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/Ipv6AdapterInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoIpv6Adapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,606 +44,564 @@
*/
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 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 = "";
+ logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);

- 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("[CISCOIPv6ADAPTER][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Failed to obtain reference to the properties and/or
logger instances.");

- private MetadataConfiguration properties = null;
+ }

- // ---------------------- caching attributes
+ logger.debug("[CiscoIpv6Adapter] Constructor started");

- private static List cachedResults = new ArrayList();
+ logger.debug("[CiscoIpv6Adapter] Constructor finished");

- // ---------------------- constructors
+ }// CiscoIpv6Adapter

- public CiscoIpv6Adapter() throws PerfSONARException {
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public List getAvailableSpecificCommands() {

- try {
+ logger.debug("[CiscoIpv6Adapter getAvailableSpecificCommands
called");

- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ return availableSpecificCommands;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoIpv6Adapter setAvailableSpecificCommand called");

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ this.availableSpecificCommands = availableSpecificCommands;

- } catch (PerfSONARException e) {
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.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("[CiscoIpv6Adapter addAvailableSpecificCommand called");

- }
+ availableSpecificCommands.add(command);

- logger.debug("[CiscoIpv6Adapter] Constructor started");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {

- logger.debug("[CiscoIpv6Adapter] Constructor finished");
+ logger.debug("[CiscoIpv6Adapter getCommand called");

- }// CiscoIpv6Adapter
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- // ---------------------- public methods
+ while (it.hasNext()) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ command = (Ipv6Command) it.next();

- logger.debug("[CiscoIpv6Adapter getAvailableSpecificCommands
called");
+ if (command.getDescription().equalsIgnoreCase(description)) {

- return availableSpecificCommands;
+ logger.debug("[CiscoIpv6Adapter Command found");
+ return command;

- }// getAvailableSpecificCommands
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }// while

- logger.debug("[CiscoIpv6Adapter setAvailableSpecificCommand
called");
+ logger.error("[CiscoIpv6Adapter 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.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{

- }// setAvailableSpecificCommands
+ logger.debug("[CiscoIpv6Adapter executeCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ if (manager != null) {

- logger.debug("[CiscoIpv6Adapter 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.ipv6.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if

- logger.debug("[CiscoIpv6Adapter getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoIpv6Adapter executeCommand finished");
+ return command;

- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }

- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- command = (Ipv6Command) it.next();
+ logger.debug("[CiscoIpv6Adapter Connect called");

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {

- logger.debug("[CiscoIpv6Adapter 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");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- }// while
+ manager = new TelnetManager(url, port, false);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));

- logger.error("[CiscoIpv6Adapter Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.debug("[CiscoIpv6Adapter Trying to connect");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");

- logger.debug("[CiscoIpv6Adapter executeCommand called");
+ logger.debug("[CiscoIpv6Adapter Login");

- if (manager != null) {
+ } catch (Exception e) {

- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
+ 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");

- 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("[CiscoIpv6Adapter executeCommand finished");
- return command;
+ return port;

- }// executeCommand
+ }

- public void connect() {
- }
+ public void setPort(int port) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;

- logger.debug("[CiscoIpv6Adapter Connect called");
+ }

- try {
+ public String getPrompt() {

- if (manager == null) {
+ return prompt;

- 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"));
+ }

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject,
"prompt"));
+ public void setPrompt(String prompt) {

- }
+ this.prompt = prompt;

- logger.debug("[CiscoIpv6Adapter Trying to connect");
+ }

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ public String getUrl() {

- logger.debug("[CiscoIpv6Adapter Login");
+ return url;

- } catch (Exception e) {
+ }

- 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");
+ 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("[CiscoIpv6Adapter 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("[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());
+ }

- public String getPrompt() {
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- return prompt;
+ }

- }
+ }

- public void setPrompt(String prompt) {
+ } catch (PerfSONARException e) {

- this.prompt = prompt;
+ logger.error("[CISCOIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- }
+ }

- public String getUrl() {
+ //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_FORWARDING, "show ipv6 forwarding"));
+ //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_ROUTE, "show ipv6 route"));

- return url;
+ logger.debug("[CiscoIpv6Adapter 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;
+ 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("[CiscoIpv6Adapter Configuring available
operations ...");
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- Iterator commands = 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, ' ');
+ }
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ t2 = resultBuffer.toString();

- token = (String) commands.next();
- if (token.contains("IPv6")) {
+ return t2.replace("" + prompt, "---END---");

- Ipv6Command command = new
Ipv6Command(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoIpv6Adapter Webservice takeAction call received");

- }
+ Metadata[] metadata = request.getMetadataArray();
+ Subject s = metadata[0].getSubject();

- //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_FORWARDING, "show ipv6 forwarding"));
- //this.addAvailableSpecificCommand(new
Ipv6Command(ActionType.MP_IPv6_ROUTE, "show ipv6 route"));
+ EndPoint endpoint = (EndPoint) s.getChildArray()[0];
+ String subject = endpoint.getValue();

- logger.debug("[CiscoIpv6Adapter Available operations
configured");
+ logger.debug("SUBJECTSTRING: " + subject);

- }
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();

- /**
- * 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("EVENTTYPESTRING: " + eventTypeString);

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();

- 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((ipv6Command.getCommand() + " " + ipv6Command
- .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"));

- StringBuffer resultBuffer = new StringBuffer(t2);
+ manager = new TelnetManager(url, port, false);

- 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("[CISCOIPv6ADAPTER][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("[CISCOIPv6ADAPTER][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("[CiscoIpv6Adapter Webservice takeAction call
received");
+ logger.error("[CISCOIPv6ADAPTER][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);
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);

- CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();
- //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)) {
+ ipv6Command.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }

- url = properties.getProperty(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ }

- manager = new TelnetManager(url, port, false);
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.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");
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();

- } catch (PerfSONARException e1) {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.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(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(ipv6Command).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 (ipv6Command.getMinParamCount() == 0) {

- //
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- Ipv6CommandInterface ipv6Command =
this.getCommand(eventTypeString);
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();

- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.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)) {
- ipv6Command.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 (ipv6Command.getParameters().size() >= ipv6Command
- .getMinParamCount()
- && ipv6Command.getParameters().size()
<= ipv6Command
- .getMaxParamCount() && valid) {
+ }

- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
+ if (temp.equalsIgnoreCase("")) {

- Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface)it.next();
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();

- 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 {

- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ 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();
+ }

- }
+ logger.info("[CiscoIpv6Adapter Command executed succesfully");

- }
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }

- if (temp.equalsIgnoreCase("")) {
+ logger.info("[CiscoIpv6Adapter Constructing response message");

- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
+ 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]);

- }
- 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(respMetaData + "");
+ logger.debug(respData + "");

- } else if (ipv6Command.getMinParamCount() == 0) {
+ //response.setSonarMetadata(request.getSonarMetadata());

+ //response.setSonarData(new Data[] { data });
+ logger.info("[CiscoIpv6Adapter takeAction finished");

- Iterator it = cachedResults.iterator();
- while (it.hasNext()) {
+ return response;
+ //return new ServiceEngineResponse();

- 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()) {
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- logger.info("CACHED RESULT RETURNED");
- temp = cachedCommand.getResult();
+ try {
+ CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();

- } else if
(cachedCommand.getTimestamp()+(caching*1000) <= System.currentTimeMillis()) {
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco1");

- logger.info("CACHED RESULT REMOVED");
- it.remove();
+ adapter.connect("cisco1");

- }
+ Ipv6CommandInterface ipv6Command;

- }
+ try {

- if (temp.equalsIgnoreCase("")) {
+ ipv6Command = adapter.getCommand("IPv6_ROUTE");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);

- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
+ } catch (PerfSONARException e) {

- }
+ //e.printStackTrace();

- } else {
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- temp = " Wrong number of parameters
detected.";
- throw new
PerfSONARException("error.mp.sshtelnet.parameter",
- "Wrong number of parameters detected.");
-
- }
-
- logger.info("[CiscoIpv6Adapter Command executed succesfully");
-
- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
-
- logger.info("[CiscoIpv6Adapter Constructing response
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]);
-
- //System.err.println(respMetaData);
- //System.err.println(respData);
-
- //response.setSonarMetadata(request.getSonarMetadata());

- //response.setSonarData(new Data[] { data });
- logger.info("[CiscoIpv6Adapter takeAction finished");
-
- return response;
- //return new ServiceEngineResponse();
-
- }
-
- // ---------------------- Stand-alond Test Method
-
- public static void main(String[] args) {
-
- try {
- CiscoIpv6Adapter adapter = new CiscoIpv6Adapter();
-
- //This private method call will include all supported
methods
- //that can be performed on the remote device
- adapter.configureCommands("cisco1");
-
- adapter.connect("cisco1");
-
- Ipv6CommandInterface ipv6Command;
-
- try {
-
- 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) {
-
- e.printStackTrace();
-
- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
-
- }
-
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoKeyIpv6Adapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,589 +43,544 @@
*
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ }// 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"));

- }// while
+ manager = new SshKeyManager(url, username, keyUrl, false);

- logger.error("[CiscoKeyIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[CiscoKeyIpv6Adapter] Trying to connect");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[CiscoKeyIpv6Adapter] Login");

- logger.debug("[CiscoKeyIpv6Adapter] executeCommand called");
+ } catch (Exception e) {

- if (manager != null) {
+ 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");

- // System.out.println("Executing command");
- 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("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ return port;

- }// executeCommand
+ }

- public void connect() {
- }
+ public void setPort(int port) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;

- logger.info("[CiscoKeyIpv6Adapter] Connect called");
+ }

- try {
+ public String getPrompt() {

- if (manager == null) {
+ return prompt;

- 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"));
+ }

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ public void setPrompt(String prompt) {

- }
+ this.prompt = prompt;

- logger.info("[CiscoKeyIpv6Adapter] Trying to
connect");
+ }

- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[CiscoKeyIpv6Adapter] Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return url;

- 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) {

- }// 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("[CiscoKeyIpv6Adapter] 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 {
+ 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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[CISCOKEYIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[CiscoKeyIpv6Adapter] 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;
+ 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("[CiscoKeyIpv6Adapter] Configuring
available operations ...");
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- Iterator commands = 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, ' ');
+ }
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ t2 = resultBuffer.toString();

- token = (String) commands.next();
- if (token.contains("IPv6_")) {
+ return t2.replace("" + prompt, "---END---");

- 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) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoKeyIpv6Adapter] Webservice takeAction call
received");

- logger.debug("[CiscoKeyIpv6Adapter] 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();

- 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"));

- 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);

- 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(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"));
+ } 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");
+ adapter.connect(subject);
+ temp = adapter.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.");
- }
+ adapter.connect(subject);
+ temp = adapter.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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/CiscoSshIpv6Adapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,580 +44,538 @@
*/
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 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 MetadataConfiguration 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");

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ return availableSpecificCommands;

- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- } catch (PerfSONARException e) {
+ logger.debug("[CiscoSshIpv6Adapter] 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.ipv6.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {

- logger.debug("[CiscoSshIpv6Adapter] Constructor started");
+ logger.debug("[CiscoSshIpv6Adapter] addAvailableSpecificCommand
called");

- logger.debug("[CiscoSshIpv6Adapter] Constructor finished");
+ availableSpecificCommands.add(command);

- }// CiscoSshIpv6Adapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {

- // ---------------------- public methods
+ logger.debug("[CiscoSshIpv6Adapter] getCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- logger.debug("[CiscoSshIpv6Adapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {

- return availableSpecificCommands;
+ command = (Ipv6Command) it.next();

- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[CiscoSshIpv6Adapter] Command found");
+ return command;

- logger.debug("[CiscoSshIpv6Adapter]
setAvailableSpecificCommand called");
+ }

- this.availableSpecificCommands = availableSpecificCommands;
+ }// while

- }// setAvailableSpecificCommands
+ logger.error("[CiscoSshIpv6Adapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{

- logger.debug("[CiscoSshIpv6Adapter]
addAvailableSpecificCommand called");
+ logger.debug("[CiscoSshIpv6Adapter] 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.ipv6.IpAdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if

- logger.debug("[CiscoSshIpv6Adapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshIpv6Adapter] executeCommand finished");
+ return command;

- Ipv6CommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ }// executeCommand
+ public void connect() {
+ }

- while (it.hasNext()) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- command = (Ipv6Command) it.next();
+ logger.info("[CiscoSshIpv6Adapter] Connect called");

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {

- logger.debug("[CiscoSshIpv6Adapter] 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");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- }// while
+ //System.out.println(username);
+ //System.out.println(password);

- logger.error("[CiscoSshIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new SshManager(url, username, password, false);

- }// getCommand
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ logger.info("[CiscoSshIpv6Adapter] Trying to connect");

- logger.debug("[CiscoSshIpv6Adapter] executeCommand called");
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");

- if (manager != null) {
+ logger.info("[CiscoSshIpv6Adapter Login");

- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ } catch (Exception e) {

- }// if
+ 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");

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshIpv6Adapter] executeCommand finished");
- return command;
+ }

- }// executeCommand
+ }// connect

- public void connect() {
- }
+ // ---------------------- field methods
+ public int getPort() {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ return port;

- logger.info("[CiscoSshIpv6Adapter] Connect called");
+ }

- try {
+ public void setPort(int port) {

- if (manager == null) {
+ this.port = port;

- 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"));
+ }

- //System.out.println(username);
- //System.out.println(password);
+ public String getPrompt() {

- manager = new SshManager(url, username,
password, false);
+ return prompt;

- }
+ }

- logger.info("[CiscoSshIpv6Adapter] Trying to
connect");
+ public void setPrompt(String prompt) {

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;

- logger.info("[CiscoSshIpv6Adapter Login");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[CiscoSshIpv6Adapter] 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("[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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[CISCOSSHIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- return url;
+ }

- }
+ logger.debug("[CiscoSshIpv6Adapter] 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, Ipv6CommandInterface
ipv6Command) {

- }
+ 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("[CiscoSshIpv6Adapter] Configuring available
operations ...");
+ String tempResult = temp.substring((ipv6Command.getCommand() + " "
+ ipv6Command.getParameterString()).length());

- Iterator commands = null;
- String token = null;
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- try {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }

- token = (String) commands.next();
- if (token.contains("IPv6")) {
+ t2 = resultBuffer.toString();

- Ipv6Command command = new
Ipv6Command(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoSshIpv6Adapter] Available operations
configured");
+ logger.info("[CiscoSshIpv6Adapter] 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();

- }
+ 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"));

- return t2.replace("" + prompt, "---END---");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- }
+ } catch (NumberFormatException e1) {

- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOSSHIPv6ADAPTER][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("[CISCOSSHIPv6ADAPTER][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("[CiscoSshIpv6Adapter] 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();
+ Ipv6CommandInterface ipv6Command = 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);

- CiscoSshIpv6Adapter adapter = new CiscoSshIpv6Adapter();
- //adapter.connect(subject);
+ 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.");
+ }

- // REPLACED
+ }

- availableSpecificCommands = new ArrayList();
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {

- try {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- url = properties.getProperty(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ Ipv6CommandInterface cachedCommand =
(Ipv6CommandInterface) it.next();

- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);
+ if
(cachedCommand.getCommand().equalsIgnoreCase(ipv6Command.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(ipv6Command.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(ipv6Command.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);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();

- //
+ }

- Ipv6CommandInterface ipv6Command =
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 (ipv6Command.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);
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();

- 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.");
- }
+ 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();

- 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()) {
+ } 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();
-
- }
+ 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 (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()) {
+ if (temp.equalsIgnoreCase("")) {

- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).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("[CiscoSshIpv6Adapter] Command executed
succesfully");
+ }

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ logger.info("[CiscoSshIpv6Adapter] Command executed succesfully");

- logger.info("[CiscoSshIpv6Adapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[CiscoSshIpv6Adapter] 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("[CiscoSshIpv6Adapter] 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("[CiscoSshIpv6Adapter] 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 {
- 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperIpv6Adapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,613 +44,569 @@
*/
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 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 MetadataConfiguration 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");

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
+ 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"));

- }// getCommand
+ manager = new TelnetManager(url, port, false);
+ ((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(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"));
+ public String getPrompt() {

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(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 ...");
+ }

- Iterator commands = 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;

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ }

- token = (String) commands.next();
- if (token.contains("IPv6")) {
+ String tempResult = temp.substring((ipv6Command.getCommand() + " "
+ ipv6Command.getParameterString()).length());

- Ipv6Command command = new
Ipv6Command(token, properties
- .getProperty(subject,
token, "command"));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- String tempResult = temp
- .substring((ipv6Command.getCommand() + " "
+ ipv6Command
-
.getParameterString()).length());
+ JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();

- 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, ' ');
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- t2 = resultBuffer.toString();
+ manager = new TelnetManager(url, port, false);

- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {

- }
+ logger.error("[JUNIPERIPv6ADAPTER][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("[JUNIPERIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- return this.serviceEngineType;
+ }

- }
+ logger.debug("[JuniperIpv6Adapter] TelnetManager created: " + url +
" " + port);

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ try {

- logger.info("[JuniperIpv6Adapter 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("[JUNIPERIPv6ADAPTER][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("[JuniperIpv6Adapter] 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);

- JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();
- //adapter.connect(subject);
+ Ipv6CommandInterface ipv6Command = this.getCommand(eventTypeString);

- availableSpecificCommands = new ArrayList();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();

- try {
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; 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"));
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);

- manager = new TelnetManager(url, port, false);
+ 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 (NumberFormatException e1) {
+ }

- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {

- } catch (PerfSONARException e1) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection
details");
+ 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.debug("[JuniperIpv6Adapter] TelnetManager created: " +
url + " "
- + port);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject, "prompt"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- } catch (PerfSONARException e) {
+ }

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ }

- }
+ if (temp.equalsIgnoreCase("")) {

- logger.debug("[JuniperIpv6Adapter] Prompt set in
TelnetManager: "
- + prompt);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();

- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ }

- Ipv6CommandInterface ipv6Command =
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 (ipv6Command.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);
+ Ipv6CommandInterface cachedCommand = (Ipv6CommandInterface)
it.next();

- 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.");
- }
+ 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();

- 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()) {
+ } 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();
-
- }
+ 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 (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()) {
+ if (temp.equalsIgnoreCase("")) {

- logger.info("CACHED RESULT REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(ipv6Command).getResult();
-
- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).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("[JuniperIpv6Adapter Command executed
succesfully");
+ }

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, ipv6Command));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperIpv6Adapter Command executed succesfully");

- logger.info("[JuniperIpv6Adapter Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, ipv6Command));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[JuniperIpv6Adapter 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();

- // System.err.println(respMetaData);
- // System.err.println(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 });
- logger.info("[JuniperIpv6Adapter takeAction finished");
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");

- return response;
- // return new ServiceEngineResponse();
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });
+ logger.info("[JuniperIpv6Adapter takeAction finished");

- }
+ return response;
+ // return new ServiceEngineResponse();

- // ---------------------- Stand-alond Test Method
+ }

- public static void main(String[] args) {
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- try {
- JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();
+ try {
+ JuniperIpv6Adapter adapter = new JuniperIpv6Adapter();

- // 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");

- Ipv6CommandInterface ipv6Command;
+ Ipv6CommandInterface ipv6Command;

- try {
+ try {

- ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
- String temp =
adapter.executeCommand(ipv6Command).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
+ ipv6Command =
adapter.getCommand("IPv6_MULTICAST_FORWARDING");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);

- System.out.println(adapter.filterResult(temp,
ipv6Command));
+ //System.out.println(adapter.filterResult(temp, ipv6Command));

- } catch (PerfSONARException e) {
+ } catch (PerfSONARException e) {

- e.printStackTrace();
+ //e.printStackTrace();

- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- }
-
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperKeyIpv6Adapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,602 +43,558 @@
*
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[JuniperKeyIpv6Adapter] 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.ip.Ipv6AdapterInterface
+ */
+ public void addAvailableSpecificCommand(Ipv6CommandInterface command) {

- }
+ logger.debug("[JuniperKeyIpv6Adapter] addAvailableSpecificCommand
called");

- logger.debug("[JuniperKeyIpv6Adapter] Constructor finished");
+ availableSpecificCommands.add(command);

- }// JuniperKeyIpv6Adapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {

- // ---------------------- public methods
+ logger.debug("[JuniperKeyIpv6Adapter] getCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ Ipv6CommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- logger
- .debug("[JuniperKeyIpv6Adapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {

- return availableSpecificCommands;
+ command = (Ipv6Command) it.next();

- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[JuniperKeyIpv6Adapter] Command found");
+ return command;

- logger
- .debug("[JuniperKeyIpv6Adapter]
setAvailableSpecificCommand called");
+ }

- this.availableSpecificCommands = availableSpecificCommands;
+ }// while

- }// setAvailableSpecificCommands
+ logger.error("[JuniperKeyIpv6Adapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void addAvailableSpecificCommand(Ipv6CommandInterface command)
{
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public Ipv6CommandInterface executeCommand(Ipv6CommandInterface command)
{

- logger
- .debug("[JuniperKeyIpv6Adapter]
addAvailableSpecificCommand called");
+ logger.debug("[JuniperKeyIpv6Adapter] executeCommand called");

- availableSpecificCommands.add(command);
+ if (manager != null) {

- }// addAvailableSpecificCommand
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface getCommand(String description)
- throws PerfSONARException {
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());

- logger.debug("[JuniperKeyIpv6Adapter] getCommand called");
+ }// if

- Ipv6CommandInterface 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 = (Ipv6Command) it.next();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ logger.info("[JuniperKeyIpv6Adapter] Connect called");

- logger.debug("[JuniperKeyIpv6Adapter] 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"));

- logger.error("[JuniperKeyIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new SshKeyManager(url, username, keyUrl, false);

- }// getCommand
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public Ipv6CommandInterface executeCommand(Ipv6CommandInterface
command) {
+ logger.info("[JuniperKeyIpv6Adapter] Trying to connect");

- logger.debug("[JuniperKeyIpv6Adapter] executeCommand called");
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[JuniperKeyIpv6Adapter] Login");

- if (manager != null) {
+ } catch (Exception e) {

- // System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ 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");

- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }

- }// if
+ }// connect

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ // ---------------------- field methods
+ public int getPort() {

- }// executeCommand
+ return port;

- public void connect() {
- }
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.Ipv6AdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public void setPort(int port) {

- logger.info("[JuniperKeyIpv6Adapter] Connect called");
+ this.port = port;

- try {
+ }

- if (manager == null) {
+ public String getPrompt() {

- 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"));
+ return prompt;

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ }

- }
+ public void setPrompt(String prompt) {

- logger.info("[JuniperKeyIpv6Adapter] Trying to
connect");
+ this.prompt = prompt;

- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[JuniperKeyIpv6Adapter] Login");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[JuniperKeyIpv6Adapter] 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 {
+ 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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[JUNIPERKEYIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- return url;
+ }

- }
+ logger.debug("[JuniperKeyIpv6Adapter] 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, Ipv6CommandInterface
ipv6Command) {

- }
+ 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("[JuniperKeyIpv6Adapter] Configuring
available operations ...");
+ while (temp.indexOf("---(more") > -1) {

- Iterator commands = null;
- String token = null;
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- try {
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- token = (String) commands.next();
- if (token.contains("IPv6_")) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);

- 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) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[JuniperKeyIpv6Adapter] 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("[JuniperKeyIpv6Adapter] 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- String tempResult;
- if (temp.length() == 0) {
- tempResult = "No response";
- } else {
- tempResult = temp;
- }
+ JuniperKeyIpv6Adapter adapter = new JuniperKeyIpv6Adapter();

- 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");
+ username = properties.getProperty(subject, "username");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- t2 = resultBuffer.toString();
+ manager = new SshKeyManager(url, username, keyUrl, false);

- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {

- }
+ logger.error("[JUNIPERKEYIPv6ADAPTER][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("[JUNIPERKEYIPv6ADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- return this.serviceEngineType;
+ }

- }
+ logger.debug("[JuniperKeyIpv6Adapter] TelnetManager 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("[JuniperKeyIpv6Adapter] 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);
+ }

- JuniperKeyIpv6Adapter adapter = new JuniperKeyIpv6Adapter();
+ if (ipv6Command.getParameters().size() >=
ipv6Command.getMinParamCount() && ipv6Command.getParameters().size() <=
ipv6Command.getMaxParamCount() && valid) {

- //adapter.connect(subject);
+ 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(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"));
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- manager = new SshKeyManager(url, username, keyUrl,
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("")) {

- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(ipv6Command).getResult();

- 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);
+ } 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) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- 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) {
+ adapter.connect(subject);
+ temp = adapter.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("[JuniperKeyIpv6Adapter] Command executed succesfully");

- logger.info("[JuniperKeyIpv6Adapter] 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);
+ datum.setDatum(filterResult(temp, ipv6Command));

- datum.setDatum(filterResult(temp, ipv6Command));
+ logger.info("[JuniperKeyIpv6Adapter] Constructing response message");

- logger.info("[JuniperKeyIpv6Adapter] 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("[JuniperKeyIpv6Adapter] takeAction finished");

- logger.info("[JuniperKeyIpv6Adapter] takeAction finished");
+ return response;

- return response;
+ }

- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- // ---------------------- Stand-alond Test Method
+ try {
+ JuniperKeyIpv6Adapter adapter = new JuniperKeyIpv6Adapter();

- 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("juniperfr");

- try {
- JuniperKeyIpv6Adapter adapter = new
JuniperKeyIpv6Adapter();
+ adapter.connect("juniperfr");

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("juniperfr");
+ Ipv6CommandInterface ipv6Command;

- adapter.connect("juniperfr");
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/adapters/JuniperSshIpv6Adapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,593 +44,552 @@
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- 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("[JuniperSshIpv6Adapter] 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("[JuniperSshIpv6Adapter] addAvailableSpecificCommand
called");

- logger.debug("[JuniperSshIpv6Adapter] Constructor started");
+ availableSpecificCommands.add(command);

- logger.debug("[JuniperSshIpv6Adapter] Constructor finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
+ */
+ public Ipv6CommandInterface getCommand(String description)
+ throws PerfSONARException {

- }// JuniperSshIpv6Adapter
+ logger.debug("[JuniperSshIpv6Adapter] 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("[JuniperSshIpv6Adapter]
getAvailableSpecificCommands called");
+ command = (Ipv6Command) it.next();

- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {

- }// getAvailableSpecificCommands
+ logger.debug("[JuniperSshIpv6Adapter] Command found");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ipv6.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }

- logger.debug("[JuniperSshIpv6Adapter]
setAvailableSpecificCommand called");
+ }// while

- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperSshIpv6Adapter] 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("[JuniperSshIpv6Adapter] executeCommand called");

- logger.debug("[JuniperSshIpv6Adapter]
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("[JuniperSshIpv6Adapter] executeCommand finished");
+ return command;

- logger.debug("[JuniperSshIpv6Adapter] 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("[JuniperSshIpv6Adapter] Connect called");

- command = (Ipv6Command) it.next();
+ try {

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ if (manager == null) {

- logger.debug("[JuniperSshIpv6Adapter] 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"));

- }
+ //System.out.println(username);
+ //System.out.println(password);

- }// while
+ manager = new SshManager(url, username, password, false);

- logger.error("[JuniperSshIpv6Adapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ }

- }// getCommand
+ logger.info("[JuniperSshIpv6Adapter] 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("[JuniperSshIpv6Adapter] executeCommand called");
+ logger.info("[JuniperSshIpv6Adapter Login");

- if (manager != null) {
+ } catch (Exception e) {

- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ 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");

- }// if
+ }

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperSshIpv6Adapter] 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("[JuniperSshIpv6Adapter] Connect called");
+ public void setPort(int port) {

- try {
+ this.port = port;

- 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");
- caching =
Integer.parseInt(properties.getProperty(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("[JuniperSshIpv6Adapter] Trying to
connect");
+ this.prompt = prompt;

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }

- logger.info("[JuniperSshIpv6Adapter Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return url;

- 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) {

- }// 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("[JuniperSshIpv6Adapter] 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("[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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[JUNIPERSSHIPv6ADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[JuniperSshIpv6Adapter] 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;
+ 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("[JuniperSshIpv6Adapter] Configuring available
operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- Iterator commands = null;
- String token = null;
+ }

- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);

- token = (String) commands.next();
- if (token.contains("IPv6_")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- Ipv6Command command = new
Ipv6Command(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[JuniperSshIpv6Adapter] 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, Ipv6CommandInterface
ipv6Command) {
+ logger.info("[JuniperSshIpv6Adapter] 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();

- 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"));

- t2 = resultBuffer.toString();
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {

- }
+ logger.error("[JUNIPERSSHIPv6ADAPTER][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("[JUNIPERSSHIPv6ADAPTER][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("[JuniperSshIpv6Adapter] 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.");
+ }

- JuniperSshIpv6Adapter adapter = new JuniperSshIpv6Adapter();
- //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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(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);
+ adapter.connect(subject);
+ temp = adapter.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()) {
+ adapter.connect(subject);
+ temp = adapter.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("[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
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- public static void main(String[] args) {
+ try {
+ JuniperSshIpv6Adapter adapter = new JuniperSshIpv6Adapter();

- try {
- JuniperSshIpv6Adapter adapter = new
JuniperSshIpv6Adapter();
+ //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");
+ Ipv6CommandInterface ipv6Command;

- Ipv6CommandInterface ipv6Command;
+ try {

- try {
+ ipv6Command = adapter.getCommand("IPv6");
+ String temp =
adapter.executeCommand(ipv6Command).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);
+ //System.out.println(temp);

- ipv6Command = adapter.getCommand("IPv6");
- 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6Command.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/ipv6/commands/Ipv6CommandInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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);
+}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/DbMetadataConfiguration.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/DbMetadataConfiguration.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/DbMetadataConfiguration.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,7 +1,11 @@
+/*
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSONAR
+ */
package org.perfsonar.service.measurementPoint.lookingGlassType.metadata;

import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;

import org.perfsonar.base.auxiliary.AuxiliaryComponentManager;
@@ -14,351 +18,326 @@
import org.perfsonar.service.base.storage.xmldb.XmlDbStorageManager;
import org.perfsonar.service.base.storage.xmldb.exist.ExistDbFactory;

-
+/**
+ * Class implementing the MetadataConfiguration interface for
+ * providing service capabilities to requestor, using a database
+ * XML-Exist Backend.
+ *
+ * @author smelis
+ */
public class DbMetadataConfiguration implements MetadataConfiguration {

- /**
- * This object provides access to metadata configuration
- */
+ /**
+ * This object provides access to metadata configuration
+ */
+ protected StorageManager existDbXmlStorageManager = null;
+ protected LoggerComponent logger = null;
+ protected ConfigurationComponent configuration = null;
+ protected String metadataFile = "";

- protected StorageManager existDbXmlStorageManager = null;
+ public DbMetadataConfiguration() throws PerfSONARException {
+ try {

- protected LoggerComponent logger = null;
+ this.logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER);

- protected ConfigurationComponent configuration = null;
+ } catch (PerfSONARException e) {

- protected String metadataFile = "";
-
- public DbMetadataConfiguration () throws PerfSONARException {
- try {
+ logger.error("[DBMETADATACONFIGURATION][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.common.no_logger",
+ "MetadataConfigurationStorageManager.constructor: " +
"Cannot get logger component");

- this.logger = (LoggerComponent)
AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.LOGGER);
+ }

- } catch (PerfSONARException e) {
+ try {

- throw new PerfSONARException(
- "error.common.no_logger",
-
"MetadataConfigurationStorageManager.constructor: "
- + "Cannot get logger component");
+ this.configuration = (ConfigurationComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.CONFIG);

- }
+ } catch (PerfSONARException e) {

- try {
+ logger.error("[DBMETADATACONFIGURATION][Constructor]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.common.no_configuration",
+ "MetadataConfigurationStorageManager.constructor: " +
"Cannot get config component");

- this.configuration =
(ConfigurationComponent)AuxiliaryComponentManager.
- getInstance().getComponent(ComponentNames.CONFIG);
+ }

- } catch (PerfSONARException e) {
+ metadataFile =
configuration.getProperty("component.mp.xmldb.metadata_file_name");
+ }

- throw new PerfSONARException(
- "error.common.no_configuration",
-
"MetadataConfigurationStorageManager.constructor: "
- + "Cannot get config component");
+ public void initStorage() throws PerfSONARException {

- }
-
- metadataFile =
configuration.getProperty("component.mp.xmldb.metadata_file_name");
- }
+ this.existDbXmlStorageManager = getStorageManager();
+ }

- public void initStorage() throws PerfSONARException {
+ public String getProperty(String property) throws PerfSONARException {
+ logger.debug("[DbMetadataConfiguration] getProperty(" + property +
") called.");

- this.existDbXmlStorageManager = getStorageManager();
- }
+ return null;
+ }

+ public String getProperty(String device, String property) throws
PerfSONARException {
+ logger.debug("[DbMetadataConfiguration] getProperty(" + device + ",
" + property + ") called.");

- public String getProperty(String property) throws PerfSONARException{
- logger.debug("[DbMetadataConfiguration] getProperty("
- + property + ") called.");
-
- return null;
- }

- public String getProperty(String device, String property) throws
PerfSONARException{
- logger.debug("[DbMetadataConfiguration] getProperty("
- + device +", "+ property + ") called.");
-
-
- String query = "";
- String result = "";
-
-
- if (property.equalsIgnoreCase("url") ||
property.equalsIgnoreCase("class_name")
- || property.equalsIgnoreCase("port") ||
property.equalsIgnoreCase("prompt")
- || property.equalsIgnoreCase("rate") ||
property.equalsIgnoreCase("username")
- || property.equalsIgnoreCase("password") ||
property.equalsIgnoreCase("cache")
- || property.equalsIgnoreCase("keyUrl") ||
property.equalsIgnoreCase("passphrase")){
- query += "declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/';\n";
- query += "for $i in doc(\"" + metadataFile +
"\")/nmwg:store/nmwg:metadata\n";
- query += "where $i/nmwg:subject=\"" + device + "\"\n";
- query += "return
fn:data($i/nmwg:parameters/nmwg:parameter[@name=\""
+ property + "\"]/@value)";
- }
-
- logger.debug("[DbMetadataConfiguration] query: " + query);
-
- Object object = null;
+ String query = "";
+ String result = "";
+
+
+ if (property.equalsIgnoreCase("url") ||
property.equalsIgnoreCase("class_name") || property.equalsIgnoreCase("port")
|| property.equalsIgnoreCase("prompt") || property.equalsIgnoreCase("rate")
|| property.equalsIgnoreCase("username") ||
property.equalsIgnoreCase("password") || property.equalsIgnoreCase("cache")
|| property.equalsIgnoreCase("keyUrl") ||
property.equalsIgnoreCase("passphrase")) {
+ query += "declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/';\n";
+ query += "for $i in doc(\"" + metadataFile +
"\")/nmwg:store/nmwg:metadata\n";
+ query += "where $i/nmwg:subject=\"" + device + "\"\n";
+ query += "return
fn:data($i/nmwg:parameters/nmwg:parameter[@name=\""
+ property + "\"]/@value)";
+ }
+
+ logger.debug("[DbMetadataConfiguration] query: " + query);
+
+ Object object = null;
try {
object = this.existDbXmlStorageManager.fetch(query);
} catch (Exception ex) {
- logger.error("MetadataConfigurationStorageManager.fetch: "
- + "Connection to xml database failed: "
- + ex.toString());
- ex.printStackTrace();
- throw new PerfSONARException(
+ logger.error("[DBMETADATACONFIGURATION][GetProperty]
MetadataConfigurationStorageManager.fetch: " + "Connection to xml database
failed: " + ex.toString());
+ //ex.printStackTrace();
+ throw new PerfSONARException(
"error.common.storage.xmldb",
- "DbMetadataConfiguration.getProperties: "
- + "Connection to xml database failed");
+ "DbMetadataConfiguration.getProperties: " + "Connection
to xml database failed");
}
String[] res = (String[]) object;
- if (res == null || res.length != 1)
- throw new PerfSONARException(
+ if (res == null || res.length != 1) {
+ throw new PerfSONARException(
"error.mp",
- "DbMetadataConfiguration.getProperty: "
- + "Result array of metadata search is null or it
contains no or too much elements");
-
+ "DbMetadataConfiguration.getProperty: " + "Result array
of metadata search is null or it contains no or too much elements");
+ }
+
result = res[0];
-
- if (result == null)
+
+ if (result == null) {
throw new PerfSONARException(
"error.mp",
- "DbMetadataConfiguration.getProperty: "
- + "Result array of metadata search in null");
-
- return result;
- }
+ "DbMetadataConfiguration.getProperty: " + "Result array
of metadata search in null");
+ }

- public String getProperty(String device, String command, String
property) throws PerfSONARException{
+ return result;
+ }

- logger.debug("[DbMetadataConfiguration] getProperty("
- + device + ", " + command + ", " + property +
") called.");
-
-
- String query = "";
- String result = "";
-
-
- if (property.equalsIgnoreCase("description") ||
property.equalsIgnoreCase("command")
- || property.equalsIgnoreCase("minParamCount")
|| property.equalsIgnoreCase("maxParamCount")
- || property.equalsIgnoreCase("caching") ||
property.equalsIgnoreCase("syntax")
- || property.equalsIgnoreCase("regex")){
- query += "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n";;
- query += "\n";
- query += "let $file := doc(\"" + metadataFile +
"\")\n";
- query += "\n";
- query += "let $ids :=\n";
- query += " for $j in
$file/nmwg:store/nmwg:metadata\n";
- query += " where $j/nmwg:subject=\"" + device +
"\"\n";
- query += " return fn:data($j/@id)\n";
- query += "\n";
- query += "for $i in $ids\n";
- query += "return
fn:data($file/nmwg:store/nmwg:data[@metadataIdRef=$i]/nmwg:key[nmwg:eventType='"
+ command +
"']/nmwg:parameters/nmwg:parameter[@name='"
+ property + "']/@value)\n";
- }
-
- logger.debug("[DbMetadataConfiguration] query: " + query);
-
- Object object = null;
+ public String getProperty(String device, String command, String
property) throws PerfSONARException {
+
+ logger.debug("[DbMetadataConfiguration] getProperty(" + device + ",
" + command + ", " + property + ") called.");
+
+
+ String query = "";
+ String result = "";
+
+
+ if (property.equalsIgnoreCase("description") ||
property.equalsIgnoreCase("command") ||
property.equalsIgnoreCase("minParamCount") ||
property.equalsIgnoreCase("maxParamCount") ||
property.equalsIgnoreCase("caching") || property.equalsIgnoreCase("syntax")
|| property.equalsIgnoreCase("regex")) {
+ query += "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n";;
+ query += "\n";
+ query += "let $file := doc(\"" + metadataFile + "\")\n";
+ query += "\n";
+ query += "let $ids :=\n";
+ query += " for $j in $file/nmwg:store/nmwg:metadata\n";
+ query += " where $j/nmwg:subject=\"" + device + "\"\n";
+ query += " return fn:data($j/@id)\n";
+ query += "\n";
+ query += "for $i in $ids\n";
+ query += "return
fn:data($file/nmwg:store/nmwg:data[@metadataIdRef=$i]/nmwg:key[nmwg:eventType='"
+ command +
"']/nmwg:parameters/nmwg:parameter[@name='"
+ property + "']/@value)\n";
+ }
+
+ logger.debug("[DbMetadataConfiguration] query: " + query);
+
+ Object object = null;
try {
object = this.existDbXmlStorageManager.fetch(query);
} catch (Exception ex) {
- logger.error("MetadataConfigurationStorageManager.fetch: "
- + "Connection to xml database failed: "
- + ex.toString());
- ex.printStackTrace();
- throw new PerfSONARException(
+
logger.error("[DBMETADATACONFIGURATION][GetProperty]MetadataConfigurationStorageManager.fetch:
" + "Connection to xml database failed: " + ex.toString());
+ //ex.printStackTrace();
+ throw new PerfSONARException(
"error.common.storage.xmldb",
- "DbMetadataConfiguration.getProperties: "
- + "Connection to xml database failed");
+ "DbMetadataConfiguration.getProperties: " + "Connection
to xml database failed");
}
-
+
String[] res = (String[]) object;
- if (res == null || res.length != 1)
- throw new PerfSONARException(
+ if (res == null || res.length != 1) {
+ throw new PerfSONARException(
"error.mp",
- "DbMetadataConfiguration.getProperty: "
- + "Result array of metadata search is null or it
contains no or too much elements");
-
+ "DbMetadataConfiguration.getProperty: " + "Result array
of metadata search is null or it contains no or too much elements");
+ }
+
result = res[0];
-
- if (result == null)
+
+ if (result == null) {
throw new PerfSONARException(
"error.mp",
- "DbMetadataConfiguration.getProperty: "
- + "Result array of metadata search is null");
-
-
- return result;
- }
-
- public List getProperties(String property) throws PerfSONARException{
+ "DbMetadataConfiguration.getProperty: " + "Result array
of metadata search is null");
+ }

- logger.debug("[DbMetadataConfiguration] getProperties("
- + property + ") called.");
-
-
- String query = "";
-
- if (property.equals(MetadataConfiguration.DEVICE_NAMES)){
- // search for all device names
- // Query:
- query += "declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/';\n";
- query += "for $i in doc(\"" + metadataFile +
"\")/nmwg:store/nmwg:metadata/nmwg:subject\n";
- query += "return data($i)";
- }

- logger.debug("[DbMetadataConfiguration] query: " + query);
-
- Object object = null;
+ return result;
+ }
+
+ public List getProperties(String property) throws PerfSONARException {
+
+ logger.debug("[DbMetadataConfiguration] getProperties(" + property +
") called.");
+
+
+ String query = "";
+
+ if (property.equals(MetadataConfiguration.DEVICE_NAMES)) {
+ // search for all device names
+ // Query:
+ query += "declare namespace
nmwg='http://ggf.org/ns/nmwg/base/2.0/';\n";
+ query += "for $i in doc(\"" + metadataFile +
"\")/nmwg:store/nmwg:metadata/nmwg:subject\n";
+ query += "return data($i)";
+ }
+
+ logger.debug("[DbMetadataConfiguration] query: " + query);
+
+ Object object = null;
try {
object = this.existDbXmlStorageManager.fetch(query);
} catch (Exception ex) {
- logger.error("DbMetadataConfiguration.getProperties: "
- + "Connection to xml database failed: "
- + ex.toString());
- ex.printStackTrace();
- throw new PerfSONARException(
+
logger.error("[DBMETADATACONFIGURATION][GetProperties]DbMetadataConfiguration.getProperties:
" + "Connection to xml database failed: " + ex.toString());
+ //ex.printStackTrace();
+ throw new PerfSONARException(
"error.common.storage.xmldb",
- "DbMetadataConfiguration.getProperties: "
- + "Connection to xml database failed");
+ "DbMetadataConfiguration.getProperties: " + "Connection
to xml database failed");
}
String[] xmlResults = (String[]) object;
-
- if (xmlResults == null)
+
+ if (xmlResults == null) {
throw new PerfSONARException(
"error.mp",
- "DbMetadataConfiguration.getProperties: "
- + "Result array of metadata search in null");
+ "DbMetadataConfiguration.getProperties: " + "Result
array of metadata search in null");
+ }

- logger.debug("DbMetadataConfiguration.getProperties: "
- + "The number of elements returned as a result of xquery
statement: "
- + xmlResults.length);
+ logger.debug("DbMetadataConfiguration.getProperties: " + "The number
of elements returned as a result of xquery statement: " + xmlResults.length);

- if (xmlResults.length == 0)
+ if (xmlResults.length == 0) {
throw new PerfSONARException(
"warning.mp.metadata_configuration",
- "DbMetadataConfiguration.getProperties: "
- + "No metadata in the metadata configuration");
+ "DbMetadataConfiguration.getProperties: " + "No metadata
in the metadata configuration");
+ }

- if (xmlResults.length == 1)
- if (xmlResults[0].trim().equals(""))
+ if (xmlResults.length == 1) {
+ if (xmlResults[0].trim().equals("")) {
throw new PerfSONARException(
"warning.mp.metadata_configuration",
- "DbMetadataConfiguration.getProperties: "
- + "No metadata in the metadata configuration");
-
+ "DbMetadataConfiguration.getProperties: " + "No
metadata in the metadata configuration");
+ }
+ }
+
ArrayList result = new ArrayList();
- for (int i = 0; i < xmlResults.length; i++)
- result.add(xmlResults[i]);
- return result;
- }
+ for (int i = 0; i < xmlResults.length; i++) {
+ result.add(xmlResults[i]);
+ }
+ return result;
+ }

- public List getProperties(String device, String property) throws
PerfSONARException{
+ public List getProperties(String device, String property) throws
PerfSONARException {

- logger.debug("[DbMetadataConfiguration] getProperty("
- + device + ", " + property + ") called.");
-
-
- String query = "";
-
- if (property.equalsIgnoreCase("commands")){
- // search for all command names for a certain device
- // Query:
- query += "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n";;
- query += "\n";
- query += "let $file := doc(\"" + metadataFile +
"\")\n";
- query += "\n";
- query += "let $ids :=\n";
- query += " for $j in
$file/nmwg:store/nmwg:metadata\n";
- query += " where $j/nmwg:subject=\"" + device +
"\"\n";
- query += " return fn:data($j/@id)\n";
- query += "\n";
- query += "for $i in $ids\n";
- query += "return
fn:data($file/nmwg:store/nmwg:data[@metadataIdRef=$i]/nmwg:key/nmwg:eventType)\n";
- }
+ logger.debug("[DbMetadataConfiguration] getProperty(" + device + ",
" + property + ") called.");

- logger.debug("[DbMetadataConfiguration] query: " + query);
-
- Object object = null;
+
+ String query = "";
+
+ if (property.equalsIgnoreCase("commands")) {
+ // search for all command names for a certain device
+ // Query:
+ query += "declare namespace
nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\";\n";;
+ query += "\n";
+ query += "let $file := doc(\"" + metadataFile + "\")\n";
+ query += "\n";
+ query += "let $ids :=\n";
+ query += " for $j in $file/nmwg:store/nmwg:metadata\n";
+ query += " where $j/nmwg:subject=\"" + device + "\"\n";
+ query += " return fn:data($j/@id)\n";
+ query += "\n";
+ query += "for $i in $ids\n";
+ query += "return
fn:data($file/nmwg:store/nmwg:data[@metadataIdRef=$i]/nmwg:key/nmwg:eventType)\n";
+ }
+
+ logger.debug("[DbMetadataConfiguration] query: " + query);
+
+ Object object = null;
try {
object = this.existDbXmlStorageManager.fetch(query);
} catch (Exception ex) {
- logger.error("DbMetadataConfiguration.getProperties: "
- + "Connection to xml database failed: "
- + ex.toString());
- ex.printStackTrace();
- throw new PerfSONARException(
+
logger.error("[DBMETADATACONFIGURATION][GetProperty]DbMetadataConfiguration.getProperties:
" + "Connection to xml database failed: " + ex.toString());
+ //ex.printStackTrace();
+ throw new PerfSONARException(
"error.common.storage.xmldb",
- "DbMetadataConfiguration.getProperties: "
- + "Connection to xml database failed");
+ "DbMetadataConfiguration.getProperties: " + "Connection
to xml database failed");
}
String[] xmlResults = (String[]) object;
-
- if (xmlResults == null)
+
+ if (xmlResults == null) {
throw new PerfSONARException(
"error.mp",
- "DbMetadataConfiguration.getProperties: "
- + "Result array of metadata search in null");
+ "DbMetadataConfiguration.getProperties: " + "Result
array of metadata search in null");
+ }

- logger.debug("DbMetadataConfiguration.getProperties: "
- + "The number of elements returned as a result of xquery
statement: "
- + xmlResults.length);
+ logger.debug("DbMetadataConfiguration.getProperties: " + "The number
of elements returned as a result of xquery statement: " + xmlResults.length);

- if (xmlResults.length == 0)
+ if (xmlResults.length == 0) {
throw new PerfSONARException(
"warning.mp.metadata_configuration",
- "DbMetadataConfiguration.getProperties: "
- + "No metadata in the metadata configuration");
+ "DbMetadataConfiguration.getProperties: " + "No metadata
in the metadata configuration");
+ }

- if (xmlResults.length == 1)
- if (xmlResults[0].trim().equals(""))
+ if (xmlResults.length == 1) {
+ if (xmlResults[0].trim().equals("")) {
throw new PerfSONARException(
"warning.mp.metadata_configuration",
- "DbMetadataConfiguration.getProperties: "
- + "No metadata in the metadata configuration");
-
+ "DbMetadataConfiguration.getProperties: " + "No
metadata in the metadata configuration");
+ }
+ }
+
ArrayList result = new ArrayList();
- for (int i = 0; i < xmlResults.length; i++)
- result.add(xmlResults[i]);
- return result;
- }
-
-
- protected XmlDbStorageManager getStorageManager()
- throws PerfSONARException {
+ for (int i = 0; i < xmlResults.length; i++) {
+ result.add(xmlResults[i]);
+ }
+ return result;
+ }

- String xmldbAccess = "http";
+ protected XmlDbStorageManager getStorageManager()
+ throws PerfSONARException {

- try {
- xmldbAccess =
-
configuration.getProperty("component.mp.xmldb.db_access");
- } catch (Exception ex) {
- throw new PerfSONARException(
- "warning.mp.metadata_configuration",
-
"DbMetadataConfiguration.getStorageManager: "
- + "Something went wrong while reading
the properties file");
- }
+ String xmldbAccess = "http";

- if (xmldbAccess == null || xmldbAccess.equals(""))
- xmldbAccess = "http";
+ try {
+ xmldbAccess =
+
configuration.getProperty("component.mp.xmldb.db_access");
+ } catch (Exception ex) {
+ logger.equals("[DBMETADATACONFIGURATION][GetStorageManager]" +
ex.getStackTrace().toString());
+ throw new PerfSONARException(
+ "warning.mp.metadata_configuration",
+ "DbMetadataConfiguration.getStorageManager: " +
"Something went wrong while reading the properties file");
+ }

-
- XmlDbDataRepository dataRepository =
- ExistDbFactory.getDataRepositoryByProperties(
- xmldbAccess.toUpperCase(),
- "component.mp.xmldb.db_uri",
- "component.mp.xmldb.db_username",
- "component.mp.xmldb.db_password");
+ if (xmldbAccess == null || xmldbAccess.equals("")) {
+ xmldbAccess = "http";
+ }

- XmlDbStorageManager storageManager =
- ExistDbFactory.getXMLStorageManager(
- xmldbAccess, dataRepository);
- storageManager.setResultType(
- XmlDbStorageManager.STRING_ARRAY_TYPE);

- return storageManager;
+ XmlDbDataRepository dataRepository =
+ ExistDbFactory.getDataRepositoryByProperties(
+ xmldbAccess.toUpperCase(),
+ "component.mp.xmldb.db_uri",
+ "component.mp.xmldb.db_username",
+ "component.mp.xmldb.db_password");

- }
-
- public static void main (String[] args) {
+ XmlDbStorageManager storageManager =
+ ExistDbFactory.getXMLStorageManager(
+ xmldbAccess, dataRepository);
+ storageManager.setResultType(
+ XmlDbStorageManager.STRING_ARRAY_TYPE);

- }
+ return storageManager;
+
+ }
+
+ public static void main(String[] args) {
+
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/MetadataConfiguration.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/MetadataConfiguration.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/metadata/MetadataConfiguration.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,3 +1,8 @@
+/*
+ * Created/Updated on Jan 8th, 2008
+ * Version Number: 1.0
+ * Project: perfSONAR
+ */
package org.perfsonar.service.measurementPoint.lookingGlassType.metadata;

import java.util.List;
@@ -2,6 +7,4 @@

-import org.ggf.ns.nmwg.base.v2_0.Key;
import org.perfsonar.base.exceptions.PerfSONARException;

-
/**
@@ -12,17 +15,17 @@
*/
public interface MetadataConfiguration {

- public static String DEVICE_NAMES = "device_names";
-
- public void initStorage() throws PerfSONARException;
-
- public String getProperty(String property) throws PerfSONARException;
-
- public String getProperty(String device, String property) throws
PerfSONARException;
-
- public String getProperty(String device, String command, String
property) throws PerfSONARException;
-
- public List getProperties(String property) throws PerfSONARException;
-
- public List getProperties(String device, String property) throws
PerfSONARException;
+ public static String DEVICE_NAMES = "device_names";
+
+ public void initStorage() throws PerfSONARException;
+
+ public String getProperty(String property) throws PerfSONARException;
+
+ public String getProperty(String device, String property) throws
PerfSONARException;
+
+ public String getProperty(String device, String command, String
property) throws PerfSONARException;
+
+ public List getProperties(String property) throws PerfSONARException;
+
+ public List getProperties(String device, String property) throws
PerfSONARException;
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/StatusAdapterInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoKeyStatusAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,592 +43,545 @@
*
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ logger.debug("[CiscoKeyStatusAdapter] 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.bgp.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {

- }
+ logger.debug("[CiscoKeyStatusAdapter] addAvailableSpecificCommand
called");

- logger.debug("[CiscoKeyStatusAdapter] Constructor finished");
+ availableSpecificCommands.add(command);

- }// CiscoKeyStatusAdapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {

- // ---------------------- public methods
+ logger.debug("[CiscoKeyStatusAdapter] getCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- logger
- .debug("[CiscoKeyStatusAdapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {

- return availableSpecificCommands;
+ command = (StatusCommand) it.next();

- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[CiscoKeyStatusAdapter] Command found");
+ return command;

- logger
- .debug("[CiscoKeyStatusAdapter]
setAvailableSpecificCommand called");
+ }

- this.availableSpecificCommands = availableSpecificCommands;
+ }// while

- }// setAvailableSpecificCommands
+ logger.error("[CiscoKeyStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {

- logger
- .debug("[CiscoKeyStatusAdapter]
addAvailableSpecificCommand called");
+ logger.debug("[CiscoKeyStatusAdapter] executeCommand called");

- availableSpecificCommands.add(command);
+ if (manager != null) {

- }// addAvailableSpecificCommand
+ logger.debug("Executing command");
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ manager.disconnect();

- logger.debug("[CiscoKeyStatusAdapter] getCommand called");
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());

- StatusCommandInterface 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 = (StatusCommand) it.next();
+ }// executeCommand
+ public void connect() {
+ }

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- logger.debug("[CiscoKeyStatusAdapter] Command
found");
- return command;
+ logger.info("[CiscoKeyStatusAdapter] Connect called");

- }
+ try {

- }// while
+ if (manager == null) {

- logger.error("[CiscoKeyStatusAdapter] 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");
+ keyUrl = properties.getProperty(subject, "keyUrl");
+ passphrase = properties.getProperty(subject, "passphrase");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- }// getCommand
+ manager = new SshKeyManager(url, username, keyUrl, false);

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ }

- logger.debug("[CiscoKeyStatusAdapter] executeCommand called");
+ logger.info("[CiscoKeyStatusAdapter] Trying to connect");

- if (manager != null) {
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[CiscoKeyStatusAdapter] Login");

- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ } catch (Exception e) {

- manager.disconnect();
+ 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");

- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }

- }// if
+ }// connect

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] executeCommand
finished");
- return command;
+ // ---------------------- field methods
+ public int getPort() {

- }// executeCommand
+ return port;

- public void connect() {
- }
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ public void setPort(int port) {

- logger.info("[CiscoKeyStatusAdapter] Connect called");
+ this.port = port;

- try {
+ }

- if (manager == null) {
+ public String getPrompt() {

- 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"));
+ return prompt;

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ }

- }
+ public void setPrompt(String prompt) {

- logger.info("[CiscoKeyStatusAdapter] Trying to
connect");
+ this.prompt = prompt;

- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[CiscoKeyStatusAdapter] Login");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[CiscoKeyStatusAdapter] 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, "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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[CISCOKEYSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- return url;
+ }

- }
+ logger.debug("[CiscoKeyStatusAdapter] 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("[CiscoKeyStatusAdapter] Configuring
available operations ...");
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());

- Iterator commands = null;
- String token = null;
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- try {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }

- token = (String) commands.next();
- if (token.contains("STATUS_")) {
+ t2 = resultBuffer.toString();

- 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) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoKeyStatusAdapter] Available
operations configured");
+ logger.info("[CiscoKeyStatusAdapter] 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ CiscoKeyStatusAdapter adapter = new CiscoKeyStatusAdapter();

- 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, ' ');
- }
+ 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"));

- t2 = resultBuffer.toString();
+ manager = new SshKeyManager(url, username, keyUrl, false);

- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {

- }
+ logger.error("[CISCOKEYSTATUSADAPTER][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("[CISCOKEYSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- return this.serviceEngineType;
+ }

- }
+ logger.debug("[CiscoKeyStatusAdapter] TelnetManager 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("[CiscoKeyStatusAdapter] Webservice
takeAction call received");
+ StatusCommandInterface statusCommand =
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)) {
+ statusCommand.addParameter(parameter);
+ } else {
+ temp = " Malicious parameters
detected.";
+ valid = false;
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Malicious parameters detected.");
+ }

- // System.out.println("EVENTTYPESTRING: " + eventTypeString);
+ }

- CiscoKeyStatusAdapter adapter = new CiscoKeyStatusAdapter();
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {

- //adapter.connect(subject);
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- availableSpecificCommands = new ArrayList();
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();

- try {
+ if
(cachedCommand.getCommand().equalsIgnoreCase(statusCommand.getCommand()) &&
cachedCommand.getParameterString().equalsIgnoreCase(statusCommand.getParameterString())
&&
cachedCommand.getDeviceName().equalsIgnoreCase(statusCommand.getDeviceName())
&& cachedCommand.getTimestamp() + (caching * 1000) >
System.currentTimeMillis()) {

- 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"));
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- manager = new SshKeyManager(url, username, keyUrl,
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("")) {

- }
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();

- 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);
+ } 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("[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
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- public static void main(String[] args) {
+ try {
+ CiscoKeyStatusAdapter adapter = new CiscoKeyStatusAdapter();

- try {
- CiscoKeyStatusAdapter adapter = new
CiscoKeyStatusAdapter();
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("junipernl");

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("junipernl");
+ adapter.connect("junipernl");

- adapter.connect("junipernl");
+ StatusCommandInterface statusCommand;

- StatusCommandInterface statusCommand;
+ try {

- try {
+ statusCommand = adapter.getCommand("STATUS_TEST");
+ String temp =
adapter.executeCommand(statusCommand).getResult();
+ ((LoggerComponent)
AuxiliaryComponentManager.getInstance().getComponent(ComponentNames.LOGGER)).info(temp);

- statusCommand =
adapter.getCommand("STATUS_TEST");
- 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoSshStatusAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,17 +1,13 @@
/*
- * 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.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;
@@ -48,588 +44,546 @@
*/
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 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
+ /*try {
+ properties.getProperties().store(new
FileOutputStream("eend.properties"), "");
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }*/

- 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 MetadataConfiguration properties = null;
-
- // ---------------------- caching attributes
+ 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 static List cachedResults = new ArrayList();
+ }

- // ---------------------- constructors
+ logger.debug("[CiscoSshStatusAdapter] Constructor started");

- public CiscoSshStatusAdapter() throws PerfSONARException {
+ logger.debug("[CiscoSshStatusAdapter] Constructor finished");

- try {
+ }// CiscoSshStatusAdapter

- logger = (LoggerComponent)
AuxiliaryComponentManager.getInstance()
- .getComponent(ComponentNames.LOGGER);
+ // ---------------------- public methods
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public List getAvailableSpecificCommands() {

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- /*try {
- properties.getProperties().store(new
FileOutputStream("eend.properties"), "");
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }*/
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[CiscoSshStatusAdapter] getAvailableSpecificCommands
called");

- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ return availableSpecificCommands;

- } catch (PerfSONARException e) {
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshYE.configuration",
- "Failed to obtain reference to the
properties and/or logger instances.");
+ logger.debug("[CiscoSshStatusAdapter] setAvailableSpecificCommand
called");

- }
+ this.availableSpecificCommands = availableSpecificCommands;

- logger.debug("[CiscoSshStatusAdapter] Constructor started");
+ }// setAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {

- logger.debug("[CiscoSshStatusAdapter] Constructor finished");
+ logger.debug("[CiscoSshStatusAdapter] addAvailableSpecificCommand
called");

- }// CiscoSshStatusAdapter
+ availableSpecificCommands.add(command);

- // ---------------------- public methods
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ logger.debug("[CiscoSshStatusAdapter] getCommand called");

- logger.debug("[CiscoSshStatusAdapter]
getAvailableSpecificCommands called");
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- return availableSpecificCommands;
+ while (it.hasNext()) {

- }// getAvailableSpecificCommands
+ command = (StatusCommand) it.next();

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ if (command.getDescription().equalsIgnoreCase(description)) {

- logger.debug("[CiscoSshStatusAdapter]
setAvailableSpecificCommand called");
+ logger.debug("[CiscoSshStatusAdapter] Command found");
+ return command;

- this.availableSpecificCommands = availableSpecificCommands;
+ }

- }// setAvailableSpecificCommands
+ }// while

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ logger.error("[CiscoSshStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- logger.debug("[CiscoSshStatusAdapter]
addAvailableSpecificCommand called");
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {

- availableSpecificCommands.add(command);
+ logger.debug("[CiscoSshStatusAdapter] executeCommand called");

- }// addAvailableSpecificCommand
+ if (manager != null) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ String temp2 = manager.executeCommand(command.getCommand() + " "
+ command.getParameterString());
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());

- logger.debug("[CiscoSshStatusAdapter] getCommand called");
+ }// if

- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoSshStatusAdapter] executeCommand finished");
+ return command;

- while (it.hasNext()) {
+ }// executeCommand
+ public void connect() {
+ }

- command = (StatusCommand) it.next();
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ logger.info("[CiscoSshStatusAdapter] Connect called");

- logger.debug("[CiscoSshStatusAdapter] 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"));

- logger.error("[CiscoSshStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ //System.out.println(username);
+ //System.out.println(password);

- }// getCommand
+ manager = new SshManager(url, username, password, false);

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ }

- logger.debug("[CiscoSshStatusAdapter] executeCommand called");
+ logger.info("[CiscoSshStatusAdapter] Trying to connect");

- if (manager != null) {
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");

- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ logger.info("[CiscoSshStatusAdapter Login");

- }// if
+ } catch (Exception e) {

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoSshStatusAdapter] executeCommand
finished");
- return command;
+ 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");

- }// executeCommand
+ }

- public void connect() {
- }
+ }// connect

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ // ---------------------- field methods
+ public int getPort() {

- logger.info("[CiscoSshStatusAdapter] Connect called");
+ return port;

- try {
+ }

- if (manager == null) {
+ public void setPort(int port) {

- 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"));
-
- //System.out.println(username);
- //System.out.println(password);
+ this.port = port;

- manager = new SshManager(url, username,
password, false);
+ }

- }
+ public String getPrompt() {

- logger.info("[CiscoSshStatusAdapter] Trying to
connect");
+ return prompt;

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ }

- logger.info("[CiscoSshStatusAdapter Login");
+ public void setPrompt(String prompt) {

- } catch (Exception e) {
+ this.prompt = prompt;

- 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");
+ }

- }
+ public String getUrl() {

- }// connect
+ return url;

- // ---------------------- field methods
+ }

- public int getPort() {
+ public void setUrl(String url) {

- return port;
+ this.url = url;

- }
+ }

- public void setPort(int 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
{

- this.port = port;
+ logger.debug("[CiscoSshStatusAdapter] Configuring available
operations ...");

- }
+ Iterator commands = null;
+ String token = null;

- public String getPrompt() {
+ try {

- return prompt;
+ commands = properties.getProperties(subject,
"commands").iterator();
+ while (commands.hasNext()) {

- }
+ token = (String) commands.next();
+ if (token.contains("STATUS")) {

- public void setPrompt(String 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());
+ }

- this.prompt = prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public String getUrl() {
+ }

- return url;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[CISCOSSHSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public void setUrl(String url) {
+ }

- this.url = url;
+ logger.debug("[CiscoSshStatusAdapter] Available operations
configured");

- }
+ }

- // ---------------------- Private methods
+ /**
+ * 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 private method adds all available commands for the device to
the
- * list of available commands
- */
- private void configureCommands(String subject) throws
PerfSONARException {
+ String temp1;
+ String temp2;
+ while (temp.indexOf(" --More-- ") > -1) {

- logger.debug("[CiscoSshStatusAdapter] Configuring available
operations ...");
+ temp1 = temp.substring(0, temp.indexOf(" --More-- "));
+ temp2 = temp.substring(temp.indexOf(" --More-- ") + 41);
+ temp = temp1 + temp2;

- Iterator commands = null;
- String token = null;
+ }

- try {
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- token = (String )commands.next();
- if (token.contains("STATUS")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- StatusCommand command = new
StatusCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[CiscoSshStatusAdapter] 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("[CiscoSshStatusAdapter] 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);

- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ EventType eventType = metadata[0].getEventType();
+ String eventTypeString = eventType.getEventType();

- String t1 = tempResult.replaceAll("\\n", "");
- // System.err.println(t1);
- String t2 = t1.replaceAll("\\r", "@@@");
- // System.err.println(t2);
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- StringBuffer resultBuffer = new StringBuffer(t2);
+ CiscoSshStatusAdapter adapter = new CiscoSshStatusAdapter();

- for (int i = 0; i < resultBuffer.length(); i++) {
- if (resultBuffer.charAt(i) < 32 ||
resultBuffer.charAt(i) > 126)
- resultBuffer.setCharAt(i, ' ');
- }
+ // REPLACED

- t2 = resultBuffer.toString();
+ availableSpecificCommands = new ArrayList();

- return t2.replace("" + prompt, "---END---");
+ try {

- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- // ---------------------- Methods from service engine interface
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- /**
- * @see ServiceEngine.java
- */
- public String getType() {
+ } catch (NumberFormatException e1) {

- return this.serviceEngineType;
+ logger.error("[CISCOSSHSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.configuration",
+ "Invalid port number in configuration");

- }
+ } catch (PerfSONARException e1) {

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ logger.error("[CISCOSSHSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- logger.info("[CiscoSshStatusAdapter] Webservice takeAction
call received");
+ }

- Metadata[] metadata = request.getMetadataArray();
- Subject s = metadata[0].getSubject();
+ logger.debug("[CiscoStatusAdapter] SshManager created: " + url + " "
+ port);

- EndPoint endpoint = (EndPoint) s.getChildArray()[0];
- String subject = endpoint.getValue();
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ configureCommands(subject);

- //System.out.println("SUBJECTSTRING: " + subjectString);
+ //

- 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();

- CiscoSshStatusAdapter adapter = new CiscoSshStatusAdapter();
- //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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(subject, "cache"));
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {

- manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), 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] SshManager created: " +
url + " "
- + port);
+ }

- //This private method call will include all supported methods
- //that can be performed on the remote device
- configureCommands(subject);
+ }

- //
+ if (temp.equalsIgnoreCase("")) {

- StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();

- Parameters parameters = metadata[0].getParameters();
- Parameter[] parametersArray = parameters.getParameterArray();
+ }

- String temp = "";
- boolean valid = true;
- if (parametersArray.length > 0) {
- for (int i = 0; i < parametersArray.length; i++) {
+ } else if (valid) {
+ valid = false;
+ temp = " Wrong number of parameters
detected.";
+ throw new PerfSONARException(
+ "error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");
+ }

- Parameter param = parametersArray[i];
- String parameter = param.getParameterValue();
- //System.out.println("PARAMETERVALUE: " +
parameter);
+ } else if (statusCommand.getMinParamCount() == 0) {

- 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.");
- }
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- }
+ StatusCommandInterface cachedCommand =
(StatusCommandInterface) it.next();

- 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()) {
+ 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
REMOVED");
- it.remove();
-
- }
-
- }
-
- if (temp.equalsIgnoreCase("")) {
-
- adapter.connect(subject);
- temp =
adapter.executeCommand(statusCommand).getResult();
-
- }
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.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 (cachedCommand.getTimestamp() + (caching * 1000)
<= System.currentTimeMillis()) {

- } else if (statusCommand.getMinParamCount() == 0) {
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- 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 (temp.equalsIgnoreCase("")) {

- 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();

- }
+ }

- logger.info("[CiscoSshStatusAdapter] Command executed
succesfully");
+ } else {

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ temp = " Wrong number of parameters detected.";
+ throw new PerfSONARException("error.mp.sshtelnet.parameter",
+ "Wrong number of parameters detected.");

- logger.info("[CiscoSshStatusAdapter] Constructing response
message");
+ }

- Message response = new Message();
+ logger.info("[CiscoSshStatusAdapter] Command executed succesfully");

- 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]);
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- logger.info("[CiscoSshStatusAdapter] takeAction finished");
+ logger.info("[CiscoSshStatusAdapter] Constructing response message");

- return response;
+ 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]);

- // ---------------------- Stand-alond Test Method
+ logger.info("[CiscoSshStatusAdapter] takeAction finished");

- public static void main(String[] args) {
+ return response;

- 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");
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- adapter.connect("cisco2");
+ try {
+ CiscoSshStatusAdapter adapter = new CiscoSshStatusAdapter();

- StatusCommandInterface statusCommand;
+ //This private method call will include all supported methods
+ //that can be performed on the remote device
+ adapter.configureCommands("cisco2");

- try {
+ adapter.connect("cisco2");

- statusCommand =
adapter.getCommand("STATUS_INTERFACE");
- 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_INTERFACE");
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/CiscoStatusAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,629 +43,584 @@
*
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// getAvailableSpecificCommands
+ /**
+ * *
+ *
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[CiscoStatusAdapter] 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.status.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {

- }
+ logger.debug("[CiscoStatusAdapter] addAvailableSpecificCommand
called");

- logger.debug("[CiscoStatusAdapter] Constructor finished");
+ availableSpecificCommands.add(command);

- }// CiscoStatusAdapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {

- // ---------------------- public methods
+ logger.debug("[CiscoStatusAdapter] getCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- logger
- .debug("[CiscoStatusAdapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {

- return availableSpecificCommands;
+ command = (StatusCommand) it.next();

- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {

- /**
- * *
- *
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[CiscoStatusAdapter] Command found");
+ return command;

- logger.debug("[CiscoStatusAdapter]
setAvailableSpecificCommand called");
+ }

- this.availableSpecificCommands = availableSpecificCommands;
+ }// while

- }// setAvailableSpecificCommands
+ logger.error("[CiscoStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {

- logger.debug("[CiscoStatusAdapter]
addAvailableSpecificCommand called");
+ logger.debug("[CiscoStatusAdapter] 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.status.StatusAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());

- logger.debug("[CiscoStatusAdapter] getCommand called");
+ }// if

- StatusCommandInterface command = null;
- Iterator it = availableSpecificCommands.iterator();
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[CiscoStatusAdapter] 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("[CiscoStatusAdapter] Connect called");

- logger.debug("[CiscoStatusAdapter] Command
found");
- return command;
+ try {

- }
+ if (manager == null) {

- }// while
+ 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);

- logger.error("[CiscoStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new TelnetManager(url, port, false);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));

- }// getCommand
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ logger.debug("[CiscoStatusAdapter] Trying to connect");

- logger.debug("[CiscoStatusAdapter] executeCommand called");
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");

- if (manager != null) {
+ logger.debug("[CiscoStatusAdapter] Login");

- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- String temp2 = manager.executeCommand(" ");
+ } catch (Exception e) {

- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ 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");

- }// if
+ }

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[CiscoStatusAdapter] executeCommand finished");
- return command;
+ }// connect

- }// executeCommand
+ // ---------------------- field methods
+ public int getPort() {

- public void connect() {
- }
+ return port;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ }

- logger.debug("[CiscoStatusAdapter] Connect called");
+ public void setPort(int port) {

- try {
+ this.port = port;

- 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);
+ public String getPrompt() {

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject,
"prompt"));
+ return prompt;

- }
+ }

- logger.debug("[CiscoStatusAdapter] Trying to
connect");
+ public void setPrompt(String prompt) {

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;

- logger.debug("[CiscoStatusAdapter] Login");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[CiscoStatusAdapter] 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("[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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[CISCOSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- 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"));

- public void setUrl(String url) {
+ logger.debug("[CiscoStatusAdapter] 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,
+ StatusCommandInterface statusCommand) {

- // ---------------------- 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("[CiscoStatusAdapter] Configuring
available operations ...");
+ }

- Iterator commands = null;
- String token = null;
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());

- try {
+ String t1 = tempResult.replaceAll("\\n", "");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "@@@");
+ logger.debug(t2);

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- token = (String) commands.next();
- if (token.contains("STATUS_")) {
+ for (int i = 0; i < resultBuffer.length(); i++) {
+ if (resultBuffer.charAt(i) < 32 || resultBuffer.charAt(i) > 126)
{
+ resultBuffer.setCharAt(i, ' ');
+ }
+ }

- StatusCommand command = new
StatusCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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
- // 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"));
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- logger.debug("[CiscoStatusAdapter] Available operations
configured");
+ logger.info("[CiscoStatusAdapter] 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ CiscoStatusAdapter adapter = new CiscoStatusAdapter();

- 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"));

- return t2.replace("" + prompt, "---END---");
+ manager = new TelnetManager(url, port, false);

- }
+ } catch (NumberFormatException e1) {

- // ---------------------- Methods from service engine interface
+ logger.error("[CISCOSTATUSADAPTER][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("[CISCOSTATUSADAPTER][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] TelnetManager created: " + url +
" " + port);

- logger.info("[CiscoStatusAdapter] 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("[CISCOSTATUSADAPTER][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("[CiscoStatusAdapter] Prompt set in TelnetManager: " +
prompt);

- CiscoStatusAdapter adapter = new CiscoStatusAdapter();
- //adapter.connect(subject);
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ configureCommands(subject);

- // REPLACED
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);

- availableSpecificCommands = new ArrayList();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();

- try {
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; 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"));
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);

- manager = new TelnetManager(url, port, false);
+ 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.");
+ }

- } catch (NumberFormatException e1) {
+ }

- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {

- } catch (PerfSONARException e1) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ 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.debug("[CiscoStatusAdapter] TelnetManager created: " +
url + " "
- + port);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject, "prompt"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- } catch (PerfSONARException e) {
+ }

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ }

- }
+ if (temp.equalsIgnoreCase("")) {

- logger.debug("[CiscoStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();

- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ }

- 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();
-
- }
+ adapter.connect(subject);
+ temp = adapter.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("[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();

- // System.err.println(respMetaData);
- // System.err.println(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 });
+ logger.debug(respMetaData + "");
+ logger.debug(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) {
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- try {
- CiscoStatusAdapter adapter = new CiscoStatusAdapter();
+ try {
+ CiscoStatusAdapter adapter = new CiscoStatusAdapter();

- // This private method call will include all
supported methods
- // that can be performed on the remote device
- adapter.configureCommands("cisco1");
+ // This private method call will include all supported methods
+ // that can be performed on the remote device
+ adapter.configureCommands("cisco1");

- adapter.connect("cisco1");
+ adapter.connect("cisco1");

- StatusCommandInterface statusCommand;
+ StatusCommandInterface statusCommand;

- try {
+ try {

- statusCommand =
adapter.getCommand("STATUS_WHO");
- String temp =
adapter.executeCommand(statusCommand).getResult();
- ((LoggerComponent)
AuxiliaryComponentManager.getInstance()
-
.getComponent(ComponentNames.LOGGER)).info(temp);
- System.out.println(temp);
+ 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) {
+ } catch (PerfSONARException e) {

- e.printStackTrace();
+ //e.printStackTrace();

- }
- } catch (PerfSONARException e) {
- e.printStackTrace();
- }
+ }
+ } catch (PerfSONARException e) {
+ //e.printStackTrace();
+ }

- }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperKeyStatusAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,603 +43,559 @@
*
*/
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 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 MetadataConfiguration 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)
{

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] addAvailableSpecificCommand
called");

- }
+ availableSpecificCommands.add(command);

- logger.debug("[JuniperKeyStatusAdapter] Constructor
finished");
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.ip.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {

- }// JuniperKeyStatusAdapter
+ logger.debug("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter]
getAvailableSpecificCommands called");
+ command = (StatusCommand) it.next();

- return availableSpecificCommands;
+ if (command.getDescription().equalsIgnoreCase(description)) {

- }// getAvailableSpecificCommands
+ logger.debug("[JuniperKeyStatusAdapter] Command found");
+ return command;

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ }

- logger
- .debug("[JuniperKeyStatusAdapter]
setAvailableSpecificCommand called");
+ }// while

- this.availableSpecificCommands = availableSpecificCommands;
+ logger.error("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] executeCommand called");

- logger
- .debug("[JuniperKeyStatusAdapter]
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("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] Connect called");

- logger.debug("[JuniperKeyStatusAdapter]
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"));

- logger.error("[JuniperKeyStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new SshKeyManager(url, username, keyUrl, false);

- }// getCommand
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.bgp.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ logger.info("[JuniperKeyStatusAdapter] Trying to connect");

- logger.debug("[JuniperKeyStatusAdapter] executeCommand
called");
+ if (passphrase == null || passphrase.equals("")) {
+ manager.connect(username, keyUrl);
+ } else {
+ manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
+ }
+ logger.info("[JuniperKeyStatusAdapter] Login");

- if (manager != null) {
+ } catch (Exception e) {

- System.out.println("Executing command");
- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ 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");

- 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.StatusAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ this.port = port;

- logger.info("[JuniperKeyStatusAdapter] Connect called");
+ }

- try {
+ public String getPrompt() {

- if (manager == null) {
+ return prompt;

- 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"));
+ }

- manager = new SshKeyManager(url, username,
keyUrl, false);
+ public void setPrompt(String prompt) {

- }
+ this.prompt = prompt;

- logger.info("[JuniperKeyStatusAdapter] Trying to
connect");
+ }

- if (passphrase == null || passphrase.equals(""))
- manager.connect(username, keyUrl);
- else manager.connect(username, keyUrl,
PasswordEncryptor.decryptPassword(passphrase));
- logger.info("[JuniperKeyStatusAdapter] Login");
+ public String getUrl() {

- } catch (Exception e) {
+ return 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");
+ }

- }
+ 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("[JuniperKeyStatusAdapter] 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 {
+ 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());
+ }

- return prompt;
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- }
+ }

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ } catch (PerfSONARException e) {

- }
+ logger.error("[JUNIPERKEYSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- public String getUrl() {
+ }

- return url;
+ logger.debug("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] Configuring
available operations ...");
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- Iterator commands = null;
- String token = null;
+ }

- try {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);

- token = (String) commands.next();
- if (token.contains("STATUS")) {
+ StringBuffer resultBuffer = new StringBuffer(t2);

- 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) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] 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();

- temp1 = temp.substring(0, temp.indexOf("---(more"));
- temp2 = temp.substring(temp.indexOf("---(more") + 36);
- temp = temp1 + temp2;
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- }
+ JuniperKeyStatusAdapter adapter = new JuniperKeyStatusAdapter();

- 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"));

- 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);

- t2 = resultBuffer.toString();
+ } catch (NumberFormatException e1) {

- return t2.replace("" + prompt, "---END---");
+ logger.error("[JUNIPERKEYSTATUSADAPTER][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("[JUNIPERKEYSTATUSADAPTER][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("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] 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) {

- JuniperKeyStatusAdapter adapter = new
JuniperKeyStatusAdapter();
+ 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(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"));
+ } 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");
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();

- }
+ }

- logger.debug("[JuniperKeyStatusAdapter] 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) {
+ adapter.connect(subject);
+ temp = adapter.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("[JuniperKeyStatusAdapter] Command executed
succesfully");

- logger.info("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] Constructing response
message");

- logger.info("[JuniperKeyStatusAdapter] 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("[JuniperKeyStatusAdapter] takeAction finished");

- logger.info("[JuniperKeyStatusAdapter] takeAction finished");
+ return response;

- return response;
+ }

- }
+ // ---------------------- Stand-alond Test Method
+ public static void main(String[] args) {

- // ---------------------- Stand-alond Test Method
+ try {
+ JuniperKeyStatusAdapter adapter = new JuniperKeyStatusAdapter();

- 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 {
- JuniperKeyStatusAdapter adapter = new
JuniperKeyStatusAdapter();
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperSshStatusAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -45,592 +44,552 @@
*/
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 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 MetadataConfiguration 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");

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ return availableSpecificCommands;

- //FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// getAvailableSpecificCommands
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- } catch (PerfSONARException e) {
+ logger.debug("[JuniperSshStatusAdapter] 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.status.IpAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {

- logger.debug("[JuniperSshStatusAdapter] Constructor started");
+ logger.debug("[JuniperSshStatusAdapter] addAvailableSpecificCommand
called");

- logger.debug("[JuniperSshStatusAdapter] Constructor
finished");
+ availableSpecificCommands.add(command);

- }// JuniperSshStatusAdapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {

- // ---------------------- public methods
+ logger.debug("[JuniperSshStatusAdapter] getCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- logger.debug("[JuniperSshStatusAdapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {

- return availableSpecificCommands;
+ command = (StatusCommand) it.next();

- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[JuniperSshStatusAdapter] Command found");
+ return command;

- logger.debug("[JuniperSshStatusAdapter]
setAvailableSpecificCommand called");
+ }

- this.availableSpecificCommands = availableSpecificCommands;
+ }// while

- }// setAvailableSpecificCommands
+ logger.error("[JuniperSshStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {

- logger.debug("[JuniperSshStatusAdapter]
addAvailableSpecificCommand called");
+ logger.debug("[JuniperSshStatusAdapter] 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.status.IpAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ }// if

- logger.debug("[JuniperSshStatusAdapter] getCommand called");
+ logger.info("NEW RESULT RETURNED");
+ cachedResults.add(command);
+ logger.debug("[JuniperSshStatusAdapter] 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.IpAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- command = (StatusCommand) it.next();
+ logger.info("[JuniperSshStatusAdapter] Connect called");

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ try {

- logger.debug("[JuniperSshStatusAdapter]
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");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- }// while
+ //System.out.println(username);
+ //System.out.println(password);

- logger.error("[JuniperSshStatusAdapter] Command NOT found");
- throw new
PerfSONARException("error.mp.sshtelnet.nosuchcommand",
- "Requested command not found");
+ manager = new SshManager(url, username, password, false);

- }// getCommand
+ }

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ logger.info("[JuniperSshStatusAdapter] Trying to connect");

- logger.debug("[JuniperSshStatusAdapter] executeCommand
called");
+ manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");

- if (manager != null) {
+ logger.info("[JuniperSshStatusAdapter Login");

- String temp2 =
manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ } catch (Exception e) {

- }// if
+ 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");

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperSshStatusAdapter] executeCommand
finished");
- return command;
+ }

- }// executeCommand
+ }// connect

- public void connect() {
- }
+ // ---------------------- field methods
+ public int getPort() {

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.IpAdapterInterface
- */
- public void connect(String subject) throws PerfSONARException {
+ return port;

- logger.info("[JuniperSshStatusAdapter] Connect called");
+ }

- try {
+ public void setPort(int port) {

- if (manager == null) {
+ this.port = port;

- 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"));
+ }

- //System.out.println(username);
- //System.out.println(password);
+ public String getPrompt() {

- manager = new SshManager(url, username,
password, false);
+ return prompt;

- }
+ }

- logger.info("[JuniperSshStatusAdapter] Trying to
connect");
+ public void setPrompt(String prompt) {

- manager.connect(username, "Username:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ this.prompt = prompt;

- logger.info("[JuniperSshStatusAdapter Login");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[JuniperSshStatusAdapter] 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("[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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[JUNIPERSSHSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- return url;
+ }

- }
+ logger.debug("[JuniperSshStatusAdapter] 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("[JuniperSshStatusAdapter] Configuring available
operations ...");
+ while (temp.indexOf("---(more") > -1) {

- Iterator commands = null;
- String token = null;
+ temp1 = temp.substring(0, temp.indexOf("---(more"));
+ temp2 = temp.substring(temp.indexOf("---(more") + 36);
+ temp = temp1 + temp2;

- try {
+ }

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ String tempResult;
+ if (temp.length() == 0) {
+ tempResult = "No response";
+ } else {
+ tempResult = temp;
+ }

- token = (String) commands.next();
- if (token.contains("STATUS_")) {
+ char c = 10;
+ String t1 = tempResult.replaceAll("" + c, "@@@");
+ logger.debug(t1);
+ String t2 = t1.replaceAll("\\r", "");
+ logger.debug(t2);

- StatusCommand command = new
StatusCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
-
//System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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("[JuniperSshStatusAdapter] 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, StatusCommandInterface
statusCommand) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.info("[JuniperSshStatusAdapter] 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();

- }
+ 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"));

- return t2.replace("" + prompt, "---END---");
+ manager = new SshManager(url, username,
PasswordEncryptor.decryptPassword(password), false);

- }
+ } catch (NumberFormatException e1) {

- // ---------------------- Methods from service engine interface
+ logger.error("[JUNIPERSSHSTATUSADAPTER][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("[JUNIPERSSHSTATUSADAPTER][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("[JuniperSshStatusAdapter] 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);

- JuniperSshStatusAdapter adapter = new
JuniperSshStatusAdapter();
- //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(subject, "url");
- port =
Integer.parseInt(properties.getProperty(subject, "port"));
- prompt = properties.getProperty(subject, "prompt");
- caching =
Integer.parseInt(properties.getProperty(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);
+ adapter.connect(subject);
+ temp = adapter.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();
-
- }
+ adapter.connect(subject);
+ temp = adapter.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("[JuniperSshStatusAdapter] Command executed
succesfully");
+ }

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperSshStatusAdapter] Command executed
succesfully");

- logger.info("[JuniperSshStatusAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[JuniperSshStatusAdapter] 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("[JuniperSshStatusAdapter] 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("[JuniperSshStatusAdapter] 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 {
- 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/adapters/JuniperStatusAdapter.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
@@ -44,638 +43,588 @@
*
*/
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 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 MetadataConfiguration 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;

- this.properties = new DbMetadataConfiguration();
- properties.initStorage();
-
- // FOR LOCAL TESTING
- availableSpecificCommands = new ArrayList();
+ }// getAvailableSpecificCommands
+ /**
+ * *
+ *
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void setAvailableSpecificCommands(List availableSpecificCommands)
{

- this.serviceEngineType =
"service.MeasurementPoint.TELNETSSHType";
+ logger.debug("[JuniperStatusAdapter] 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.status.StatusAdapterInterface
+ */
+ public void addAvailableSpecificCommand(StatusCommandInterface command) {

- }
+ logger.debug("[JuniperStatusAdapter] addAvailableSpecificCommand
called");

- logger.debug("[JuniperStatusAdapter] Constructor finished");
+ availableSpecificCommands.add(command);

- }// JuniperStatusAdapter
+ }// addAvailableSpecificCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface getCommand(String description)
+ throws PerfSONARException {

- // ---------------------- public methods
+ logger.debug("[JuniperStatusAdapter] getCommand called");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public List getAvailableSpecificCommands() {
+ StatusCommandInterface command = null;
+ Iterator it = availableSpecificCommands.iterator();

- logger
- .debug("[JuniperStatusAdapter]
getAvailableSpecificCommands called");
+ while (it.hasNext()) {

- return availableSpecificCommands;
+ command = (StatusCommand) it.next();

- }// getAvailableSpecificCommands
+ if (command.getDescription().equalsIgnoreCase(description)) {

- /**
- * *
- *
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void setAvailableSpecificCommands(List
availableSpecificCommands) {
+ logger.debug("[JuniperStatusAdapter] Command found");
+ return command;

- logger
- .debug("[JuniperStatusAdapter]
setAvailableSpecificCommand called");
+ }

- this.availableSpecificCommands = availableSpecificCommands;
+ }// while

- }// setAvailableSpecificCommands
+ logger.error("[JuniperStatusAdapter] Command NOT found");
+ throw new PerfSONARException("error.mp.sshtelnet.nosuchcommand",
+ "Requested command not found");

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public void addAvailableSpecificCommand(StatusCommandInterface
command) {
+ }// getCommand
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public StatusCommandInterface executeCommand(StatusCommandInterface
command) {

- logger
- .debug("[JuniperStatusAdapter]
addAvailableSpecificCommand called");
+ logger.debug("[JuniperStatusAdapter] executeCommand called");

- availableSpecificCommands.add(command);
+ if (manager != null) {

- }// addAvailableSpecificCommand
+ manager.executeCommand(command.getCommand() + " " +
command.getParameterString());

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface getCommand(String description)
- throws PerfSONARException {
+ String temp2 = manager.executeCommand(" ");

- logger.debug("[JuniperStatusAdapter] getCommand called");
+ command.setResult(temp2);
+ command.setTimestamp(System.currentTimeMillis());

- StatusCommandInterface 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 = (StatusCommand) it.next();
+ }// executeCommand
+ public void connect() {
+ }

- if
(command.getDescription().equalsIgnoreCase(description)) {
+ /**
+ * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
+ */
+ public void connect(String subject) throws PerfSONARException {

- logger.debug("[JuniperStatusAdapter] Command
found");
- return command;
+ logger.debug("[JuniperStatusAdapter] Connect called");

- }
+ try {

- }// while
+ if (manager == null) {

- logger.error("[JuniperStatusAdapter] 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"));

- }// getCommand
+ manager = new TelnetManager(url, port, false);
+ ((TelnetManager)
manager).setPrompt(properties.getProperty(subject, "prompt"));

- /**
- * @see
org.perfsonar.service.measurementPoint.lookingGlassType.status.StatusAdapterInterface
- */
- public StatusCommandInterface executeCommand(StatusCommandInterface
command) {
+ }

- logger.debug("[JuniperStatusAdapter] executeCommand called");
+ logger.debug("[JuniperStatusAdapter] Trying to connect");

- if (manager != null) {
+ manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
+ logger.debug("[JuniperStatusAdapter] Login");

- manager.executeCommand(command.getCommand() + " "
- + command.getParameterString());
+ } catch (Exception e) {

- String temp2 = manager.executeCommand(" ");
+ 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");

- command.setResult(temp2);
- command.setTimestamp(System.currentTimeMillis());
+ }

- }// if
+ }// connect

- logger.info("NEW RESULT RETURNED");
- cachedResults.add(command);
- logger.debug("[JuniperStatusAdapter] 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("[JuniperStatusAdapter] Connect called");
+ this.port = port;

- try {
+ }

- if (manager == null) {
+ public String getPrompt() {

- 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"));
+ return prompt;

- manager = new TelnetManager(url, port, false);
- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject,
"prompt"));
+ }

- }
+ public void setPrompt(String prompt) {

- logger.debug("[JuniperStatusAdapter] Trying to
connect");
+ this.prompt = prompt;

- manager.connect(username, "login:",
PasswordEncryptor.decryptPassword(password), "Password:");
- logger.debug("[JuniperStatusAdapter] Login");
+ }

- } catch (Exception e) {
+ public String getUrl() {

- 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");
+ 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("[JuniperStatusAdapter] 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;
+ 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());
+ }

- }
+ command.setDeviceName(subject);
+ this.addAvailableSpecificCommand(command);

- public void setPrompt(String prompt) {
+ }

- this.prompt = prompt;
+ }

- }
+ } catch (PerfSONARException e) {

- public String getUrl() {
+ logger.error("[JUNIPERSTATUSADAPTER][ConfigureCommands]" +
e.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve commands");

- 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"));

- public void setUrl(String url) {
+ logger.debug("[JuniperStatusAdapter] 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,
+ StatusCommandInterface statusCommand) {

- // ---------------------- 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("[JuniperStatusAdapter] Configuring
available operations ...");
- // System.out.println("[JuniperStatusAdapter] Configuring
available
- // operations ...");
+ }

- Iterator commands = 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;

- commands = properties.getProperties(subject,
"commands").iterator();
- while (commands.hasNext()) {
+ }

- token = (String) commands.next();
- if (token.contains("STATUS_")) {
+ String tempResult = temp.substring((statusCommand.getCommand() + "
" + statusCommand.getParameterString()).length());

- //
System.out.println(properties.getProperty("service.mp."+subject+".commands."+token));
- StatusCommand command = new
StatusCommand(token, properties
- .getProperty(subject,
token, "command"));
- try {
- //
System.out.println("service.mp."+subject+".commands."+token+".minParamCount");
- int minParamCount =
Integer.parseInt(properties
-
.getProperty(subject, token, "minParamCount"));
-
command.setMinParamCount(minParamCount);
- } catch (PerfSONARException e1) {
- }
- try {
- int maxParamCount =
Integer.parseInt(properties
-
.getProperty(subject, 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();
+ logger.debug("PROMPT: " + prompt);

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve commands");
+ return t2.replace("" + prompt, "---END---");

- }
+ }

- // 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"));
+ // ---------------------- Methods from service engine interface
+ /**
+ * @see ServiceEngine.java
+ */
+ public String getType() {

- logger.debug("[JuniperStatusAdapter] 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,
- StatusCommandInterface statusCommand) {
+ /**
+ * @see ServiceEngine.java
+ */
+ public Message takeAction(String actionType, Message request)
+ throws PerfSONARException {

- String temp1;
- String temp2;
- while (temp.indexOf(" --More-- ") > -1) {
+ logger.info("[JuniperStatusAdapter] 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();

- }
+ logger.debug("EVENTTYPESTRING: " + eventTypeString);

- String tempResult = temp
- .substring((statusCommand.getCommand() + "
" + statusCommand
-
.getParameterString()).length());
+ JuniperStatusAdapter adapter = new JuniperStatusAdapter();

- 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, ' ');
- }
+ url = properties.getProperty(subject, "url");
+ port = Integer.parseInt(properties.getProperty(subject, "port"));
+ prompt = properties.getProperty(subject, "prompt");
+ caching = Integer.parseInt(properties.getProperty(subject,
"cache"));

- t2 = resultBuffer.toString();
- System.out.println("PROMPT: " + prompt);
+ manager = new TelnetManager(url, port, false);

- return t2.replace("" + prompt, "---END---");
+ } catch (NumberFormatException e1) {

- }
+ logger.error("[JUNIPERSTATUSADAPTER][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("[JUNIPERSTATUSADAPTER][TakeAction]" +
e1.getStackTrace().toString());
+ throw new PerfSONARException("error.mp.sshtelnet.configuration",
+ "Unable to retrieve connection details");

- return this.serviceEngineType;
+ }

- }
+ logger.debug("[JuniperStatusAdapter] TelnetManager created: " + url
+ " " + port);

- /**
- * @see ServiceEngine.java
- */
- public Message takeAction(String actionType, Message request)
- throws PerfSONARException {
+ try {

- logger
- .info("[JuniperStatusAdapter] 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("[JUNIPERSTATUSADAPTER][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("[JuniperStatusAdapter] 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);

- JuniperStatusAdapter adapter = new JuniperStatusAdapter();
- //adapter.connect(subject);
+ StatusCommandInterface statusCommand =
this.getCommand(eventTypeString);

- availableSpecificCommands = new ArrayList();
+ Parameters parameters = metadata[0].getParameters();
+ Parameter[] parametersArray = parameters.getParameterArray();

- try {
+ String temp = "";
+ boolean valid = true;
+ if (parametersArray.length > 0) {
+ for (int i = 0; i < parametersArray.length; 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"));
+ Parameter param = parametersArray[i];
+ String parameter = param.getParameterValue();
+ logger.debug("PARAMETERVALUE: " + parameter);

- manager = new TelnetManager(url, port, false);
+ 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.");
+ }

- } catch (NumberFormatException e1) {
+ }

- e1.printStackTrace();
- throw new PerfSONARException(
- "error.mp.sshtelnet.configuration",
- "Invalid port number in
configuration");
+ if (statusCommand.getParameters().size() >=
statusCommand.getMinParamCount() && statusCommand.getParameters().size() <=
statusCommand.getMaxParamCount() && valid) {

- } catch (PerfSONARException e1) {
+ Iterator it = cachedResults.iterator();
+ while (it.hasNext()) {

- e1.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve connection details");
+ 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.debug("[JuniperStatusAdapter] TelnetManager created: "
+ url
- + " " + port);
+ logger.info("CACHED RESULT RETURNED");
+ temp = cachedCommand.getResult();

- try {
+ } else if (cachedCommand.getTimestamp() + (caching *
1000) <= System.currentTimeMillis()) {

- ((TelnetManager) manager).setPrompt(properties
- .getProperty(subject, "prompt"));
+ logger.info("CACHED RESULT REMOVED");
+ it.remove();

- } catch (PerfSONARException e) {
+ }

- e.printStackTrace();
- throw new
PerfSONARException("error.mp.sshtelnet.configuration",
- "Unable to retrieve prompt");
+ }

- }
+ if (temp.equalsIgnoreCase("")) {

- logger.debug("[JuniperStatusAdapter] Prompt set in
TelnetManager: "
- + prompt);
+ adapter.connect(subject);
+ temp = adapter.executeCommand(statusCommand).getResult();

- // This private method call will include all supported methods
- // that can be performed on the remote device
- configureCommands(subject);
+ }

- 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();
-
- }
+ adapter.connect(subject);
+ temp = adapter.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("[JuniperStatusAdapter] Command executed
succesfully");
+ }

- Datum datum = new Datum();
- if (valid)
- datum.setDatum(filterResult(temp, statusCommand));
- else
- datum.setDatum(temp);
+ logger.info("[JuniperStatusAdapter] Command executed succesfully");

- logger.info("[JuniperStatusAdapter] Constructing response
message");
+ Datum datum = new Datum();
+ if (valid) {
+ datum.setDatum(filterResult(temp, statusCommand));
+ } else {
+ datum.setDatum(temp);
+ }

- Message response = new Message();
+ logger.info("[JuniperStatusAdapter] 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();

- // System.err.println(respMetaData);
- // System.err.println(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 });
+ logger.debug(respMetaData + "");
+ logger.debug(respData + "");

- logger.info("[JuniperStatusAdapter] takeAction finished");
+ // response.setSonarMetadata(request.getSonarMetadata());
+ // response.setSonarData(new Data[] { data });

- return response;
- // return new ServiceEngineResponse();
+ logger.info("[JuniperStatusAdapter] takeAction finished");

- }
+ return response;
+ // return new ServiceEngineResponse();

- // ---------------------- Stand-alond Test Method
+ }

- public static void main(String[] args) {
+ // ---------------------- Stand-alond Test Method
+ 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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommand.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/lookingGlassType/status/commands/StatusCommandInterface.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/common/RemoteManager.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -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;
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshKeyManager.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,6 +1,6 @@
/*
- * 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;
@@ -12,7 +12,6 @@
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 +28,252 @@
*/
public class SshKeyManager implements RemoteManager {

- // ------------------------------------- class - fields
+ // ------------------------------------- class - fields
+ private JSch jsch = null;
+ private Session session = null;
+ private UserInfo ui = new MyUserInfo();
+ private String url = null;
+ private String userName = null;
+ private String keyUrl = null;
+ private LoggerComponent logger = null;
+ private boolean connected = false;

- private JSch jsch = null;
+ public SshKeyManager(String url, String userName, String keyUrl,
+ boolean connect) {

- private Session session = null;
+ super();
+ this.url = url;
+ this.userName = userName;
+ this.keyUrl = keyUrl;

- 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

- if (connect) {
+ public void connect() throws PerfSONARException {

- try {
+ logger.debug("[SshKeyManager] connecting initiatec ...");

- connect(userName, keyUrl);
+ try {

- } catch (PerfSONARException e) {
+ //Create a new Client for communication
+ jsch = new JSch();

- logger
- .error("[SshKeyManager]
AuthenticationException during connection");
+ //Set key identity file
+ jsch.addIdentity(keyUrl);

- }
+ //Create session
+ session = jsch.getSession(userName, url, 22);

- } // connect
+ //Set user info
+ session.setUserInfo(ui);

- } // SshKeyManager
+ //Connect
+ session.connect();

- public void connect() throws PerfSONARException {
+ connected = true;

- logger.debug("[SshKeyManager] connecting initiatec ...");
+ logger.debug("[SshKeyManager] Connection established");

- try {
+ } catch (JSchException e) {

- //Create a new Client for communication
- jsch = new JSch();
+ logger.error("[SSHKEYMANAGER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "[SshKeyManager] An error occured");

- //Set key identity file
- jsch.addIdentity(keyUrl);
+ }

- //Create session
- session = jsch.getSession(userName, url, 22);
+ } //connect

- //Set user info
- session.setUserInfo(ui);
+ public void connect(String userName, String loginPrompt, String passwd,
+ String passwdPrompt) throws PerfSONARException {

- //Connect
- session.connect();
+ connect(userName, passwd);

- connected = true;
+ } //connect

- logger.debug("[SshKeyManager] Connection
established");
+ public void connect(String username, String keyUrl)
+ throws PerfSONARException {

- } catch (JSchException e) {
+ logger.debug("[SshKeyManager] connecting initiated ...");

- e.printStackTrace();
- throw new PerfSONARException(
- "[SshKeyManager] An error occured");
+ try {

- }
+ //Create a new Client for communication
+ jsch = new JSch();

- } //connect
+ //Set key identity file
+ jsch.addIdentity(keyUrl);

- public void connect(String userName, String loginPrompt, String
passwd,
- String passwdPrompt) throws PerfSONARException {
+ //Create session
+ session = jsch.getSession(userName, url, 22);

- connect(userName, passwd);
+ //Set user info
+ session.setUserInfo(ui);

- } //connect
+ //Connect
+ session.connect();

- public void connect(String username, String keyUrl)
- throws PerfSONARException {
+ connected = true;

- logger.debug("[SshKeyManager] connecting initiated ...");
+ logger.debug("[SshKeyManager] Connection established");

- try {
+ } catch (JSchException e) {

- //Create a new Client for communication
- jsch = new JSch();
+ logger.error("[SSHKEYMANAGER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "[SshKeyManager] An error occured");

- //Set key identity file
- jsch.addIdentity(keyUrl);
+ }

- //Create session
- session = jsch.getSession(userName, url, 22);
+ } //connect

- //Set user info
- session.setUserInfo(ui);
+ public void connect(String username, String keyUrl, String passphrase)
throws PerfSONARException {

- //Connect
- session.connect();
+ logger.debug("[SshKeyManager] connecting initiated ...");

- connected = true;
+ try {

- logger.debug("[SshKeyManager] Connection
established");
+ //Create a new Client for communication
+ jsch = new JSch();

- } catch (JSchException e) {
+ //Set key identity file
+ jsch.addIdentity(keyUrl, passphrase);

- e.printStackTrace();
- throw new PerfSONARException(
- "[SshKeyManager] An error occured");
+ //Create session
+ session = jsch.getSession(userName, url, 22);

- }
+ //Set user info
+ session.setUserInfo(ui);

- } //connect
+ //Connect
+ session.connect();

- public void connect(String username, String keyUrl, String
- passphrase) throws PerfSONARException {
+ connected = true;

- logger.debug("[SshKeyManager] connecting initiated ...");
+ logger.debug("[SshKeyManager] Connection established");

- try {
+ } catch (JSchException e) {

- //Create a new Client for communication
- jsch = new JSch();
+ logger.error("[SSHKEYMANAGER][Connect]" +
e.getStackTrace().toString());
+ throw new PerfSONARException(
+ "[SshKeyManager] An error occured");

- //Set key identity file
- jsch.addIdentity(keyUrl, passphrase);
+ }

- //Create session
- session = jsch.getSession(userName, url, 22);
+ } //connect

- //Set user info
- session.setUserInfo(ui);
+ public Channel getSshSessionChannel() {

- //Connect
- session.connect();
+ try {

- connected = true;
+ return session.openChannel("exec");

- logger.debug("[SshKeyManager] Connection
established");
+ } catch (JSchException e) {

- } catch (JSchException e) {
+ logger.error("[SSHKEYMANAGER][GetSshChannel]" +
e.getStackTrace().toString());
+ return null;
+ }

- e.printStackTrace();
- throw new PerfSONARException(
- "[SshKeyManager] An error occured");
+ }// getSshSessionChannel
+ public String executeCommand(String command) {

- }
+ try {
+ Channel channel = session.openChannel("exec");
+ ((ChannelExec) channel).setCommand(command);
+ channel.setInputStream(null);
+ ((ChannelExec) channel).setErrStream(System.err);

- } //connect
+ InputStream in = channel.getInputStream();

- public Channel getSshSessionChannel() {
+ channel.connect();

- try {
+ 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);
+ logger.debug(new String(tmp, 0, i));
+ }
+ if (channel.isClosed()) {
+ logger.debug("exit-status: " + channel.getExitStatus());
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (Exception ee) {
+ logger.error("[SSHKEYMANAGER][ExecuteCommand]" +
ee.getStackTrace().toString());
+ }
+ }
+ channel.disconnect();
+ session.disconnect();
+ return result;
+ } catch (JSchException e) {
+ logger.error("[SSHKEYMANAGER][ExecuteCommand]" +
e.getStackTrace().toString());
+ return "An error occured";
+ } catch (IOException e) {
+ logger.error("[SSHKEYMANAGER][ExecuteCommand]" +
e.getStackTrace().toString());
+ return "An error occured";
+ }

- return session.openChannel("exec");
+ } //executeCommand

- } catch (JSchException e) {
+ public void disconnect() {

- e.printStackTrace();
- return null;
- }
+ session.disconnect();

- }// getSshSessionChannel
+ } // disconnect

- public String executeCommand(String command) {
+ public static class MyUserInfo implements UserInfo {

- try {
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
- channel.setInputStream(null);
- ((ChannelExec) channel).setErrStream(System.err);
+ public String getPassword() {
+ return null;
+ }

- InputStream in = channel.getInputStream();
+ public boolean promptYesNo(String str) {
+ return true;
+ }

- channel.connect();
+ public String getPassphrase() {
+ 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";
- }
+ public boolean promptPassphrase(String message) {
+ return true;
+ }

- } //executeCommand
+ public boolean promptPassword(String message) {
+ return true;
+ }

- public void disconnect() {
-
- session.disconnect();
-
- } // disconnect
-
- public static class MyUserInfo implements UserInfo {
- public String getPassword() {
- return null;
- }
-
- 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);
- }
- }
-
+ public void showMessage(String message) {
+ //System.err.println(message);
+ }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/ssh/SshManager.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,7 +1,7 @@
/*
- * 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;

@@ -12,7 +12,6 @@
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 +32,241 @@
*/
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 JSch jsch = null;
+ // ---------------------- constructors
+ public SshManager(String url, String userName, String password,
+ boolean connect) {

- private Session session = null;
+ super();
+ this.url = url;
+ this.userName = userName;
+ this.password = password;
+ 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 {
+ 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();

- public void connect(String username, String keyUrl, String
- passphrase) throws PerfSONARException {
+ 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);
+ logger.debug(new String(tmp, 0, i));
+ }
+ if (channel.isClosed()) {
+ logger.debug("exit-status: " + channel.getExitStatus());
+ break;
+ }
+ try {
+ Thread.sleep(1000);
+ } catch (Exception ee) {
+ logger.error("[SSHMANAGER][ExecuteCommand]" +
ee.getStackTrace().toString());
+ }
+ }
+ channel.disconnect();
+ session.disconnect();
+ logger.debug("result: " + result);
+ return result;
+ } catch (JSchException e) {
+ logger.error("[SSHMANAGER][ExecuteCommand]" +
e.getStackTrace().toString());
+ return "An Error Occured";
+ } catch (IOException e) {
+ logger.error("[SSHMANAGER][ExecuteCommand]" +
e.getStackTrace().toString());
+ 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) {
+ public static class MyUserInfo implements UserInfo {

- e.printStackTrace();
- return null;
- }
+ String passwd;

- }// getSshChannel
+ public MyUserInfo(String passwd) {

- /**
- * Executes the command in the remote machine over the Ssh connection
- *
- * @param cmd
- * command
- */
- public String executeCommand(String cmd) {
+ super();
+ this.passwd = passwd;

- String result = "";
+ }

- try {
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(cmd);
- channel.setInputStream(null);
- ((ChannelExec) channel).setErrStream(System.err);
+ public String getPassword() {
+ return passwd;
+ }

- InputStream in = channel.getInputStream();
+ public boolean promptYesNo(String str) {
+ return true;
+ }

- channel.connect();
+ public String getPassphrase() {
+ return null;
+ }

- 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";
- }
+ public boolean promptPassphrase(String message) {
+ return true;
+ }

- }// executeCommand
+ public boolean promptPassword(String message) {
+ return true;
+ }

-
- /**
- * 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);
- }
- }
-
-
+ public void showMessage(String message) {
+ //System.err.println(message);
+ }
+ }
}

Modified:
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
===================================================================
---
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
2008-01-08 16:24:06 UTC (rev 3193)
+++
trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint/remote/telnet/TelnetManager.java
2008-01-08 22:34:04 UTC (rev 3194)
@@ -1,6 +1,6 @@
/*
- * 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;
@@ -11,7 +11,6 @@
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 +26,199 @@
*/
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 TelnetWrapper telnet = null;
+ // ---------------------- constructors
+ public TelnetManager(String url, int port, boolean connect) {

- 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;

- // ---------------------- 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
-
- /**
- * 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 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);
+ telnet.setPrompt(prompt);
+ logger.debug("prompt: " + prompt);
+ connected = true;

-
- //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
+ logger.debug("[TelnetManager] Connection established");

- /**
- * Closing and disconnection management
- *
- */
- public void disconnect() {
+ }//connect
+ public void connect(String username, String keyUrl, String passphrase)
+ throws PerfSONARException {

- if (connected) {
-
- try {
-
- telnet.disconnect();
- connected = false;
-
- } catch (IOException e) {
-
- logger.error("[TelnetManager] Disconnection
failed");
- logger.error("[TelnetManager] " +
e.getStackTrace().toString());
-
- }
- }//connected
+ connect(username, keyUrl);

- }//disconnect
+ }//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) {

- public void connect(String userName, String passwd) throws
PerfSONARException {
+ this.prompt = prompt;

- connect(userName, "Username:", passwd, "Password:");
-
- }
+ if (telnet != null) {
+ telnet.setPrompt(prompt);
+ }
+
+ }
+
+ /**
+ * 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);
+
+
+ //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
+ /**
+ * Closing and disconnection management
+ *
+ */
+ public void disconnect() {
+
+ 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:");
+
+ }
}



  • perfsonar: r3194 - in trunk/geant2_java-sshtelnet-mp/src/main/java/org/perfsonar/service/measurementPoint: lookingGlassType/bgp lookingGlassType/bgp/adapters lookingGlassType/bgp/commands lookingGlassType/encryption lookingGlassType/engine/adapters lookingGlassType/engine/commands lookingGlassType/ip lookingGlassType/ip/adapters lookingGlassType/ip/commands lookingGlassType/ipv6 lookingGlassType/ipv6/adapters lookingGlassType/ipv6/commands lookingGlassType/metadata lookingGlassType/status lookingGlassType/status/adapters lookingGlassType/status/commands remote/common remote/ssh remote/telnet, svnlog, 01/08/2008

Archive powered by MHonArc 2.6.16.

Top of Page