perfsonar-dev - perfsonar: r2539 - in branches/SSHTelnet-MP-RELEASE: conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters
Subject: perfsonar development work
List archive
perfsonar: r2539 - in branches/SSHTelnet-MP-RELEASE: conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters
Chronological Thread
- From:
- To:
- Subject: perfsonar: r2539 - in branches/SSHTelnet-MP-RELEASE: conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters
- Date: Thu, 12 Jul 2007 10:00:57 -0400
Author: melis
Date: 2007-07-12 10:00:56 -0400 (Thu, 12 Jul 2007)
New Revision: 2539
Modified:
branches/SSHTelnet-MP-RELEASE/conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.class
branches/SSHTelnet-MP-RELEASE/src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
Log:
source did not update properly last time
Modified:
branches/SSHTelnet-MP-RELEASE/conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.class
===================================================================
(Binary files differ)
Modified:
branches/SSHTelnet-MP-RELEASE/src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
===================================================================
---
branches/SSHTelnet-MP-RELEASE/src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2007-07-12 13:46:49 UTC (rev 2538)
+++
branches/SSHTelnet-MP-RELEASE/src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters/ServicePropertiesConfigurator.java
2007-07-12 14:00:56 UTC (rev 2539)
@@ -2,6 +2,10 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@@ -9,58 +13,67 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.StringTokenizer;
public class ServicePropertiesConfigurator {
- public static void doStuff(String propertiesfilename) {
+ String[] lines;
+ String previousDevices;
+
+ private static String TEMPFILE = "selectedcommands.sshtemp";
+ private static String MINIMUM_PACKAGE = "minimumpackage.txt";
+
+ public ServicePropertiesConfigurator() {
+ lines = new String[3];
+ }
+
+ public void doStuff(String outputFile) {
+
try {
+ BufferedReader br = new BufferedReader(new
InputStreamReader(
+ System.in));
+
BufferedWriter out = null;
- out = new BufferedWriter(new
FileWriter(propertiesfilename, true));
+ out = new BufferedWriter(new FileWriter(outputFile,
true));
- BufferedReader br = new BufferedReader(new
InputStreamReader(
- System.in));
List devices = new ArrayList();
-
- String previousDevices = new String(); // de devices
die in de opgegeven service.properties zaten
-
+
+ previousDevices = new String(); // devices defined
in given service.properties file
+
List types = new ArrayList();
List commands = new ArrayList();
-
- List previousCommands = new ArrayList(); // lijst van
de commands per device die in de opgegeven
- // service.properties zaten (ook in String formaat)
-
+
+ List previousCommands = new ArrayList(); // list of
commands for every device in given
+ // service.properties (also in String format)
+
List allCommands = new ArrayList();
-
-
- //
out.write("service.ls.registration_file="+propertiesfilename+"XML.xml\n");
out.write("service.ls.registration_file=\n");
System.out.println();
System.out
-
.println("|---------------------------------------------|");
+
.println("|---------------------------------------------|");
System.out
- .println("| Configuration of the
devicesTelnet / SSH MP |");
+ .println("| Configuration of the devicesTelnet / SSH
MP |");
System.out
-
.println("|---------------------------------------------|");
+
.println("|---------------------------------------------|");
System.out.println();
System.out
- .println("Do you already have a
manually edited service.configuration files available ? (yes/no)");
+ .println("Do you already have a manually edited
service.properties files available ? (yes/no)");
String previous = "";
previous = br.readLine();
while (!previous.equalsIgnoreCase("yes")
&& !previous.equalsIgnoreCase("no")) {
- System.out.println("Please reply with yes/no
!");
+ System.out.println("Please reply with
yes/no!");
previous = br.readLine();
}
- if (previous.equalsIgnoreCase("yes")) {
-
+ if (previous.equalsIgnoreCase("yes")) { // manually
edited service.properties
System.out.println();
System.out
- .println("Please enter the
path to this configuration file");
+ .println("Please enter the path to this
configuration file");
String file = br.readLine();
BufferedReader previousIn = null;
previousIn = new BufferedReader(new
FileReader(file));
@@ -85,34 +98,218 @@
line = previousIn.readLine();
}
- } else{
- //} if (true) {
- 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.");
+
+ out.close();
+ } else { // answer == no
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);
+ .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();
}
- String devicesString = "";
- if (devices.size() > 0) {
- Iterator it = devices.iterator();
- devicesString += it.next();
- while (it.hasNext())
- devicesString += "," +
it.next();
-
- if (previousDevices.equals(""))
-
out.write("service.mp.devices=" + devicesString + "\n");
- else out.write("service.mp.devices="
+ previousDevices +"," + devicesString + "\n");
-
+ 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...");
+
+ parseCSVFile(previous, outputFile);
+
+ System.out.println("Parsing done.");
+
+ } else { // answer == no
+
+ askManually(outputFile); // manually
provide configuration information
+ }
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void parseCSVFile(String file, String outputFile) {
+ try {
+ BufferedWriter out = null;
+ out = new BufferedWriter(new FileWriter(outputFile,
true));
+
+ // Read all lines from txt file
+ lines = readLinesFromFile(file);
+
+ StringTokenizer tok;
+ StringTokenizer deviceTok;
+ String deviceInfo;
+
+ String device;
+ String deviceType;
+
+ for (int i=0; i<lines.length; i++){
+ //System.out.println(" Writing: Line
"+(i+1)+": "+lines[i]);
+ //out.write("Line "+(i+1)+":
"+lines[i]+"\n");
+ tok = new StringTokenizer(lines[i],"%%%");
+
+ // First the device info
+ deviceInfo = tok.nextToken();
+ deviceTok = new
StringTokenizer(deviceInfo,"@@@");
+ device = deviceTok.nextToken();
+ deviceType = deviceTok.nextToken();
+ if
(deviceType.equalsIgnoreCase("quaggatelnet")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.QuaggaAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".password=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
"bgp.port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
"bgp.prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
"bgp.password=" + deviceTok.nextToken() + "\n");
+ } else if
(deviceType.equalsIgnoreCase("ciscotelnet")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".username=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".password=" + deviceTok.nextToken() + "\n");
+ } else if
(deviceType.equalsIgnoreCase("ciscossh")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".username=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".password=" + deviceTok.nextToken() + "\n");
+ } else if
(deviceType.equalsIgnoreCase("ciscokey")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".username=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".keyUrl=" + deviceTok.nextToken() + "\n");
+ } else if
(deviceType.equalsIgnoreCase("junipertelnet")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".username=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".password=" + deviceTok.nextToken() + "\n");
+ } else if
(deviceType.equalsIgnoreCase("juniperssh")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".username=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".password=" + deviceTok.nextToken() + "\n");
+ } else if
(deviceType.equalsIgnoreCase("juniperkey")) {
+ out.write("service.mp."+ device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter\n");
+ out.write("service.r.mp." + device +
".url=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".port=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".prompt=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".rate=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".username=" + deviceTok.nextToken() + "\n");
+ out.write("service.r.mp." + device +
".keyUrl=" + deviceTok.nextToken() + "\n");
+
+ } else {
+ System.out.println("There was an
unknown device type in the csv file: "+deviceType);
+ }
+
+ File tempFile =
File.createTempFile(device+"commands", ".tmp");
+ DataOutputStream dos = new
DataOutputStream(new FileOutputStream(tempFile, true));
+
+ while (tok.hasMoreTokens()) {
+ //Then write all command info to a
temporary file
+
+
+ dos.writeBytes(tok.nextToken()+"\n");
+ dos.flush();
+ }
+
+ dos.close();
+ //Then use this temporary file for writing
all command info
+ addSelectedCommandsToConfig(device,
outputFile, tempFile.toString());
+ }
+
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private String[] readLinesFromFile(String file) {
+ ArrayList<String> lines = new ArrayList<String>();
+
+ 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);
+ }
+
+ private void askManually(String outputFile) {
+ try{
+ BufferedReader br = new BufferedReader(new
InputStreamReader(
+ System.in));
+
+ BufferedWriter out = null;
+ out = new BufferedWriter(new FileWriter(outputFile,
true));
+
+ List devices = new ArrayList();
+
+ List types = new ArrayList();
+ List commands = new ArrayList();
+
+ // service.properties (also in String format)
+
+ List allCommands = new ArrayList();
+
+ 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);
+ }
+
+ String devicesString = "";
+ if (devices.size() > 0) {
+ Iterator it = devices.iterator();
+ System.out.println(devices.size() + " devices
added.");
+ //devicesString += it.next();
+ //while (it.hasNext()) {
+
+
System.out.println("");
System.out
- .println("Choose one
of the following types of equipment for every ");
+ .println("Choose one of the following
types of equipment for every ");
System.out.println("device specified
previously ...");
System.out.println("1) Quagga -
Password Login (Telnet)");
System.out.println("2) Cisco -
Password Login (Telnet)");
@@ -123,683 +320,627 @@
System.out.println("7) Juniper -
Key-based Login (SSH)");
System.out.println();
Iterator it2 = devices.iterator();
-
+
String device = null;
while (it2.hasNext()) {
device = (String) it2.next();
System.out.println(device +
": ");
input = br.readLine();
+ boolean invalid = true;
+ while (invalid) {
+ try {
+ int t =
Integer.parseInt(input);
+ if (t <= 7 &&
t > 0)
+
invalid = false;
+ else {
+
System.out.println("Please provide a number between 1 and 7.");
+ input
= br.readLine();
+ }
+ } catch
(NumberFormatException e) {
+ invalid =
true;
+
System.out.println("Please provide a number between 1 and 7.");
+ input =
br.readLine();
+ }
+ }
types.add(input);
-
+
if
(input.equalsIgnoreCase("1"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.QuaggaAdapter\n");
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.QuaggaAdapter\n");
else if
(input.equalsIgnoreCase("2"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter\n");
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoAdapter\n");
else if
(input.equalsIgnoreCase("3"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter\n");
-
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoSshAdapter\n");
+
else if
(input.equalsIgnoreCase("4"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter\n");
-
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.CiscoKeyAdapter\n");
+
else if
(input.equalsIgnoreCase("5"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter\n");
-
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperAdapter\n");
+
else if
(input.equalsIgnoreCase("6"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter\n");
-
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperSshAdapter\n");
+
else if
(input.equalsIgnoreCase("7"))
out
-
.write("service.mp."
-
+ device
-
+
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter\n");
+ .write("service.mp."
+ +
device
+ +
".class_name=org.perfsonar.service.measurementPoint.lookingGlassType.engine.adapters.JuniperKeyAdapter\n");
}
System.out.println();
-
+
System.out.println("According to the
chosen type of device and access method, " +
"some\nmore questions
will be asked to configure the URL, port, username,\n" +
"password or key,
prompt and access-rate (Here you can specify what\n" +
- "the minimum interval
has to be between requests (in ms)).");
+ "the minimum interval has to be
between requests (in ms)).");
//System.out
// .println("Now, some
access parameters will be asked ...");
System.out.println();
-
- it = devices.iterator();
- int index = -1;
- String type = "";
- 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();
-
- if
(type.equalsIgnoreCase("1")) {
-
System.out.println("Please give the url for device: "
+ //}
+ it = devices.iterator();
+ int index = -1;
+ String type = "";
+ //String device = "";
+ while (it.hasNext()) {
+ device = (String) it.next();
+ index = devices.indexOf(device);
+ type = (String) types.get(index);
+
+ //devicesString += it.next() + ",";
+ devicesString +=device + ",";
+ //System.out.println("devicesString:
"+devicesString);
+ //if (previousDevices.equals(""))
+ //
out.write("service.mp.devices=" +
devicesString.substring(0,devicesString.length()-1) + "\n");
+ //else
out.write("service.mp.devices=" + previousDevices +"," + devicesString +
"\n");
+
+ System.out.println(device);
+ System.out.println("======");
+ System.out.println();
+
+ if (type.equalsIgnoreCase("1")) {
+ System.out.println("Please
give the url for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".url=" + input
+ + "\n");
+ System.out.println("Please
give the port for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".port=" + input
+ + "\n");
+ System.out
+ .println("Please give the
prompt for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".prompt=" + input
+ + "\n");
+ System.out
+ .println("Please give the
access rate for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".rate=" + input
+ + "\n");
+ 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();
-
out.write("service.r.mp." + device + ".url=" + input
- +
"\n");
-
System.out.println("Please give the port for device: "
- +
device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".port=" + input
- +
"\n");
+ }
+ out.write("service.r.mp." +
device + ".password="
+ + input +
"\n");
+ System.out
+ .println("Please give the
bgp-daemon port for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + "bgp.port="
+ + input +
"\n");
+ System.out
+ .println("Please give the
bgp-daemon prompt for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + "bgp.prompt="
+ + input +
"\n");
+ System.out
+ .println("Please give the
bgp-daemon password for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + "bgp.password="
+ + input +
"\n");
+ } else if (type.equalsIgnoreCase("2")
+ ||
type.equalsIgnoreCase("3")
+ ||
type.equalsIgnoreCase("5")
+ ||
type.equalsIgnoreCase("6")) {
+ System.out.println("Please
give the url for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".url=" + input
+ + "\n");
+ System.out.println("Please
give the port for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".port=" + input
+ + "\n");
+ System.out
+ .println("Please give the
prompt for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".prompt=" + input
+ + "\n");
+ System.out
+ .println("Please give the
access rate for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".rate=" + input
+ + "\n");
+ System.out
+ .println("Please give the
username for device: "
+ + device + ":
");
+ input = br.readLine();
+ while (input == null ||
input.equals("")){
System.out
-
.println("Please give the prompt for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".prompt=" + input
- +
"\n");
- System.out
-
.println("Please give the access rate for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".rate=" + input
- +
"\n");
- 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();
- }
-
out.write("service.r.mp." + device + ".password="
- +
input + "\n");
- System.out
-
.println("Please give the bgp-daemon port for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + "bgp.port="
- +
input + "\n");
- System.out
-
.println("Please give the bgp-daemon prompt for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + "bgp.prompt="
- +
input + "\n");
- System.out
-
.println("Please give the bgp-daemon password for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + "bgp.password="
- +
input + "\n");
- } else if
(type.equalsIgnoreCase("2")
- ||
type.equalsIgnoreCase("3")
- ||
type.equalsIgnoreCase("5")
- ||
type.equalsIgnoreCase("6")) {
-
System.out.println("Please give the url for device: "
+ .println("You have to
provide a username. " +
+
"Please give the username for device: "
+
device + ": ");
input = br.readLine();
-
out.write("service.r.mp." + device + ".url=" + input
- +
"\n");
-
System.out.println("Please give the port for device: "
- +
device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".port=" + input
- +
"\n");
+ }
+ out.write("service.r.mp." +
device + ".username="
+ + input +
"\n");
+ System.out
+ .println("Please give the
password for device: "
+ + device + ":
");
+ input = br.readLine();
+ while (input == null ||
input.equals("")){
System.out
-
.println("Please give the prompt for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".prompt=" + input
- +
"\n");
- System.out
-
.println("Please give the access rate for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".rate=" + input
- +
"\n");
- 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();
- }
-
out.write("service.r.mp." + device + ".username="
- +
input + "\n");
- 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();
- }
-
out.write("service.r.mp." + device + ".password="
- +
input + "\n");
- } else if
(type.equalsIgnoreCase("4")
- ||
type.equalsIgnoreCase("7")) {
-
System.out.println("Please give the url for device: "
+ .println("You have to
provide a password. " +
+
"Please give the password for device: "
+
device + ": ");
input = br.readLine();
-
out.write("service.r.mp." + device + ".url=" + input
- +
"\n");
-
System.out.println("Please give the port for device: "
- +
device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".port=" + input
- +
"\n");
- System.out
-
.println("Please give the prompt for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".prompt=" + input
- +
"\n");
- System.out
-
.println("Please give the access rate for device: "
-
+ device + ": ");
- input = br.readLine();
-
out.write("service.r.mp." + device + ".rate=" + input
- +
"\n");
- 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();
- }
-
out.write("service.r.mp." + device + ".username="
- +
input + "\n");
- System.out
-
.println("Please give the path to the public ssh key for device: "
-
+ device + ": ");
- input = br.readLine();
- while (input == null
|| input.equals("")){
- System.out
-
.println("You have to provide a path to the public ssh key. " +
-
"Please give the the path to the public ssh key for device: "
-
+ device + ": ");
- input =
br.readLine();
- }
-
out.write("service.r.mp." + device + ".keyUrl=" + input
- +
"\n");
-
}
-
- out.write("service.r.mp." +
device + ".cache=0\n");
- System.out.println();
- }
- System.out
- .println("Enter the
name of the commands you want the users to be able to\n" +
-
"execute on the device one by one for every device, to end the list, enter
\"STOP\"!");
- System.out.println("You can choose
these names yourself");
- System.out
- .println("Start the
command with \"BGP_\" for BGP-commands");
- System.out
- .println("Start the
command with \"IP_\" for IP-commands");
- System.out
- .println("Start the
command with \"IPv6_\" for IPv6-commands");
- System.out
- .println("Start the
command with \"STATUS_\" for STATUS-commands");
-
- String lastCommands = "";
- String lastDevice = "";
- List lastCommandsList = new
ArrayList();
-
- input = "";
- boolean first = true;
- it = devices.iterator();
- while (it.hasNext()) {
- input = "";
- commands = new ArrayList();
- System.out.println();
- device = (String) it.next();
- System.out.println(device);
- System.out.println("======");
- if (!first) {
+ out.write("service.r.mp." +
device + ".password="
+ + input +
"\n");
+ } else if (type.equalsIgnoreCase("4")
+ ||
type.equalsIgnoreCase("7")) {
+ System.out.println("Please
give the url for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".url=" + input
+ + "\n");
+ System.out.println("Please
give the port for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".port=" + input
+ + "\n");
+ System.out
+ .println("Please give the
prompt for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".prompt=" + input
+ + "\n");
+ System.out
+ .println("Please give the
access rate for device: "
+ + device + ":
");
+ input = br.readLine();
+ out.write("service.r.mp." +
device + ".rate=" + input
+ + "\n");
+ System.out
+ .println("Please give the
username for device: "
+ + device + ":
");
+ input = br.readLine();
+ while (input == null ||
input.equals("")){
System.out
-
.println("Do you want the use the same commands as configured for the
previous device? (yes/[no])");
+ .println("You have to
provide a username. " +
+
"Please give the username for device: "
+ +
device + ": ");
input = br.readLine();
}
- System.out.println();
- first = false;
-
- if
(!input.equalsIgnoreCase("yes")) {
-
System.out.println("Enter the commands!");
- while
(!input.equalsIgnoreCase("STOP")) {
- input =
br.readLine();
- if (input !=
null && !input.equals("") && !input.equalsIgnoreCase("STOP"))
-
commands.add(input);
- }
-
- String commandString
= "";
- if (commands.size() >
0) {
- Iterator it3
= commands.iterator();
- commandString
+= it3.next();
- while
(it3.hasNext())
-
commandString += "," + it3.next();
- }
-
- lastCommands =
"service.mp." + device + ".commands="
- +
commandString + "\n";
- lastDevice = device;
- if
(previousDevices.contains(device)){
- Iterator
previousCommandsIt = previousCommands.iterator();
- while
(previousCommandsIt.hasNext()){
-
String prevComm = (String) previousCommandsIt.next();
- if
(prevComm.contains("."+device+".")){
-
out.write(prevComm+","+commandString+"\n");
- }
- }
-
- }else{
-
out.write("service.mp." + device + ".commands="
- +
commandString + "\n");
- }
- } else {
-
-
commands.addAll(lastCommandsList);
-
out.write(lastCommands.replaceAll(lastDevice, device));
- lastCommands =
lastCommands.replaceAll(lastDevice,
-
device);
- lastDevice = device;
-
- }
-
- lastCommandsList.clear();
-
lastCommandsList.addAll(commands);
- allCommands.add(commands);
-
- }
-
- System.out.println();
-
- System.out
- .println("Now, the
device specific commands will be asked ");
- System.out
- .println("according
to the commands configured previously");
- System.out
- .println("Also,
limitations on the number of parameters that ");
- System.out.println("can be supplied
are asked here ...");
- System.out
- .println("The last
information to be supplied is the syntax ");
- System.out
- .println("of the
commands, their textual description and the ");
- System.out
- .println("the
possibilty to specify a regular expression for ");
- System.out
- .println("the
parameters corresponding to that command. ");
- System.out.println();
-
- it = devices.iterator();
- Iterator it4 = null;
- List deviceCommands = null;
- first = true;
- input = "";
- String propertiesString = "";
- while (it.hasNext()) {
- System.out.println();
- device = (String) it.next();
-
- System.out.println(device);
- System.out.println("======");
- if (!first) {
+ out.write("service.r.mp." +
device + ".username="
+ + input +
"\n");
+ System.out
+ .println("Please give the
path to the public ssh key for device: "
+ + device + ":
");
+ input = br.readLine();
+ while (input == null ||
input.equals("")){
System.out
-
.println("Do you want the use the same properties as configured for the
previous device? (yes/[no])");
+ .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();
}
- System.out.println();
- first = false;
-
- if
(!input.equalsIgnoreCase("yes")) {
- propertiesString = "";
- index =
devices.indexOf(device);
- deviceCommands =
(ArrayList) allCommands.get(index);
- it4 =
deviceCommands.iterator();
- String command;
- while (it4.hasNext())
{
- command =
(String) it4.next();
- System.out
-
.println("Device specific command to be executed for command "
-
+ command + ": ");
- input =
br.readLine();
-
out.write("service.mp." + device + ".commands."
-
+ command + "=" + input + "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command + "=" + input
-
+ "\n";
- System.out
-
.println("Minimum number of parameters for command "
-
+ command + " [0]: ");
- input =
br.readLine();
- if
(!input.equalsIgnoreCase("")) {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".minParamCount=" + input
-
+ "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command
-
+ ".minParamCount=" + input + "\n";
- }
-
- System.out
-
.println("Maximum number of parameters for command "
-
+ command + " [0]: ");
- input =
br.readLine();
- if
(!input.equalsIgnoreCase("")) {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".maxParamCount=" + input
-
+ "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command
-
+ ".maxParamCount=" + input + "\n";
- }
-
-
System.out.println("Caching time (ms) " + command
-
+ " [0]: ");
- input =
br.readLine();
- if
(!input.equalsIgnoreCase("")) {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".caching=" + input + "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command + ".caching="
-
+ input + "\n";
- } else {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".caching=0\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command
-
+ ".caching=0\n";
- }
-
- System.out
-
.println("Textual description of the command "
-
+ command + " [none]: ");
- input =
br.readLine();
- if
(!input.equalsIgnoreCase("")) {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".description=" + input
-
+ "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command
-
+ ".description=" + input + "\n";
- }
-
-
System.out.println("Syntax rules for the command "
-
+ command + " [none]: ");
- input =
br.readLine();
- if
(!input.equalsIgnoreCase("")) {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".syntax=" + input + "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command + ".syntax="
-
+ input + "\n";
- }
-
- System.out
-
.println("Comma seperated string of regexes for "
-
+ command + " [none]: ");
- input =
br.readLine();
- if
(!input.equalsIgnoreCase("")) {
-
out.write("service.mp." + device + ".commands."
-
+ command + ".regex=" + input + "\n");
-
propertiesString += "service.mp." + device
-
+ ".commands." + command + ".regex="
-
+ input + "\n";
- }
-
- }
-
- lastDevice = device;
- }
-
- else {
-
-
out.write(propertiesString.replaceAll(lastDevice,
-
device));
- propertiesString =
propertiesString.replaceAll(
-
lastDevice, device);
- lastDevice = device;
-
- }
-
- System.out.println();
+ out.write("service.r.mp." +
device + ".keyUrl=" + input
+ + "\n");
+
}
- }
- System.out.println();
- System.out.println("That's all folks!");
- }
- out.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ out.write("service.r.mp." + device +
".cache=0\n");
+ System.out.println();
- }
-/*
- public static void createServiceStorageXML(String propertiesFileName,
- String outputFileName) {
- Properties properties = null;
- String tempFileName = outputFileName + "temp";
+ 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();
+ }
- try {
+ if (input.equals("yes")){ // use
predefined set
- properties = new Properties();
- // create an input stream to read the config file
- FileInputStream in = new
FileInputStream(propertiesFileName);
+ 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;
+ }
+ }
- // load properties from the config file
- properties.load(in);
+ File tempFile =
File.createTempFile(device+"minimum", ".tmp");
- // close the input stream
- in.close();
+ DataOutputStream tempout =
new DataOutputStream(new FileOutputStream(tempFile, true));
- } catch (Exception e) {
- }
+ File minimumFile;
+ if
(type.equalsIgnoreCase("1")){
+ minimumFile = new
File("conf/quagga"+MINIMUM_PACKAGE);
+ if
(!minimumFile.exists())
+ minimumFile =
new File("../conf/quagga"+MINIMUM_PACKAGE);
+ } else if
(type.equalsIgnoreCase("2") || type.equalsIgnoreCase("3")
+ ||
type.equalsIgnoreCase("4")){
+ minimumFile = new
File("conf/cisco"+MINIMUM_PACKAGE);
+ if
(!minimumFile.exists())
+ minimumFile =
new File("../conf/cisco"+MINIMUM_PACKAGE);
+ } else { // type == 5 or type
== 6 or type == 7
+ minimumFile = new
File("conf/juniper"+MINIMUM_PACKAGE);
+ if
(!minimumFile.exists())
+ minimumFile =
new File("../conf/juniper"+MINIMUM_PACKAGE);
+ }
+ BufferedReader tempbr = new
BufferedReader(new FileReader(minimumFile));
- Store store = new Store();
- store.setId("store1");
+ String in = tempbr.readLine();
- Data[] respData;
- Metadata[] respMetaData;
+ while (in != null &&
!in.equals("")) {
+
tempout.writeBytes(in.replace("@@@cache@@@", "@@@"+cachetime+"@@@")+"\n");
+ in =
tempbr.readLine();
+ }
- StringTokenizer it = new StringTokenizer(properties
- .getProperty("service.mp.devices"), ",");
+
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
+ } else {
- String token = null;
- int tokencounter = 0;
- String innerToken = null;
- StringTokenizer tokenizer = null;
+ System.out.println("\nYou
will now be given the opportunity to select\n" +
+ "the commands you wish the MP
supports.");
+ if
(type.equalsIgnoreCase("2") || type.equalsIgnoreCase("3")
+ ||
type.equalsIgnoreCase("4")) { // Cisco device
+ File tempFile =
File.createTempFile("ciscominimum",".tmp");
+
System.out.println("\nFirst you can choose which IP-commands you wish to be
supported:");
+
selectCommands("cisco", "ip", tempFile.toString());
+
System.out.println("Select which IPv6-commands you wish to be supported:");
+
selectCommands("cisco", "ipv6", tempFile.toString());
+
System.out.println("Select which status commands you wish to be supported:");
+
selectCommands("cisco", "status", tempFile.toString());
+
System.out.println("Select which BGP-commands you wish to be supported:");
+
selectCommands("cisco", "bgp", tempFile.toString());
- respMetaData = new Metadata[it.countTokens()];
- respData = new Data[it.countTokens()];
+
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
- Subject subject = null;
- EventType eventType = null;
- Datum datum = null;
+ tempFile.delete();
+ } else if
(type.equalsIgnoreCase("5") || type.equalsIgnoreCase("6")
+ ||
type.equalsIgnoreCase("7")) { // Juniper device
+ File tempFile =
File.createTempFile("ciscominimum",".tmp");
+
System.out.println("\nFirst you can choose which IP-commands you wish to be
supported:");
+
selectCommands("juniper", "ip", tempFile.toString());
+
System.out.println("Select which IPv6-commands you wish to be supported:");
+
selectCommands("juniper", "ipv6", tempFile.toString());
+
System.out.println("Select which status commands you wish to be supported:");
+
selectCommands("juniper", "status", tempFile.toString());
+
System.out.println("Select which BGP-commands you wish to be supported:");
+
selectCommands("juniper", "bgp", tempFile.toString());
- while (it.hasMoreTokens()) {
+
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
+ tempFile.delete();
+ } else if
(type.equalsIgnoreCase("1")) { // Quagga device
+ File tempFile =
File.createTempFile("ciscominimum",".tmp");
+
System.out.println("\nFirst you can choose which IP-commands you wish to be
supported:");
+
selectCommands("quagga", "ip", tempFile.toString());
+
System.out.println("Select which IPv6-commands you wish to be supported:");
+
selectCommands("quagga", "ipv6", tempFile.toString());
+
System.out.println("Select which status commands you wish to be supported:");
+
selectCommands("quagga", "status", tempFile.toString());
+
System.out.println("Select which BGP-commands you wish to be supported:");
+
selectCommands("quagga", "bgp", tempFile.toString());
+
addSelectedCommandsToConfig(device, outputFile, tempFile.toString());
+ tempFile.delete();
+ } else { // Shouldn't happen
+
System.out.println("ERROR - Not a valid device.");
+ }
+ }
+ }
+ if (previousDevices.equals(""))
+ out.write("service.mp.devices=" +
devicesString.substring(0,devicesString.length()-1) + "\n");
+ else out.write("service.mp.devices=" +
previousDevices +"," + devicesString + "\n");
+ }
+ out.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
- token = (String) it.nextToken();
+ System.out.println();
+ System.out.println("That's all folks!");
+ }
- respMetaData[tokencounter] = new Metadata();
- respMetaData[tokencounter].setId("metadata" +
tokencounter);
+ 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());
- subject = new Subject();
- subject.setId("subject" + tokencounter);
- subject.setSubject(token);
+ BufferedReader br = new BufferedReader(new
FileReader(file));
+ StringTokenizer tok = null;
- Parameters metaParams = new Parameters();
- metaParams.setId("metaParams" + tokencounter);
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(System.in));
- Parameter metaparam = new Parameter();
- metaparam.setParameterName("url");
-
metaparam.setParameterValue(properties.getProperty("service.r.mp."
- + token + ".url"));
+ String name = "";
+ String command = "";
+ String descr = "";
+ String syntax = "";
+ int index = 1;
- metaParams.addChild(metaparam);
+ 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();
+ }
- respMetaData[tokencounter].addChild(subject);
- respMetaData[tokencounter].addChild(metaParams);
+ 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;
+ }
+ }
- tokenizer = new StringTokenizer(properties
- .getProperty("service.mp." + token +
".commands"), ",");
- respData[tokencounter] = new Data();
- respData[tokencounter].setId("data" + tokencounter);
-
respData[tokencounter].setMetadataIdRef(respMetaData[tokencounter]
- .getId());
+ //File outputfile = new File("temp/" + device
+ "" + TEMPFILE);
+ DataOutputStream dos = new
DataOutputStream(new FileOutputStream(outFile, true));
- while (tokenizer.hasMoreTokens()) {
+ 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();
+ }
- innerToken = tokenizer.nextToken();
+ br.close();
+ dos.close();
+ }
+ System.out.println("\nChoosen commands temporarily
saved to file...\n");
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ }
- datum = new Datum();
+ }
- eventType = new EventType();
- eventType.addText(innerToken);
- // System.out.println(innerToken);
- Parameters params = new Parameters();
- params.setId("params" + tokencounter);
+ public void addSelectedCommandsToConfig(String device, String
outputFile, String inputFile) {
+ File inputfile = new File(inputFile);
- Parameter param1 = new Parameter();
- param1.setId("param1-" + tokencounter);
- param1.setParameterName("description");
-
param1.setParameterValue(properties.getProperty("service.mp."
- + token + ".commands." +
innerToken + ".description"));
+ String input = "";
- Parameter param2 = new Parameter();
+ try {
+ //add selected commands to the configuration
+ File outputfile = new File(outputFile);
+ DataOutputStream out = new DataOutputStream(new
FileOutputStream(outputfile, true));
- param2.setId("param2-" + tokencounter);
- param2.setParameterName("syntax");
-
param2.setParameterValue(properties.getProperty("service.mp."
- + token + ".commands." +
innerToken + ".syntax"));
+ BufferedReader br = new BufferedReader(new
FileReader(inputfile));
- Parameter param3 = new Parameter();
- param3.setId("param3-" + tokencounter);
- param3.setParameterName("command");
-
param3.setParameterValue(properties.getProperty("service.mp."
- + token + ".commands." +
innerToken));
- params.addChild(param1);
- params.addChild(param2);
- params.addChild(param3);
+ input = br.readLine();
- datum.addChild(eventType);
- datum.addChild(params);
+ String command = "";
+ String realCommand = "";
+ String minParamCount = "";
+ String maxParamCount = "";
+ String cache = "";
+ String description = "";
+ String syntax = "";
+ String regExp = "";
- respData[tokencounter].addChild(datum);
+ StringTokenizer tok;
- }
+ String commandList = "";
- store.setMetadata(respMetaData[tokencounter]);
- store.setData(respData[tokencounter]);
- tokencounter++;
+ while (input != null && !input.equals("")){
+ tok = new StringTokenizer(input, "@@@");
- }
+ command = tok.nextToken();
+ realCommand = tok.nextToken();
+ minParamCount = tok.nextToken();
+ maxParamCount = tok.nextToken();
+ cache = tok.nextToken();
+ description = tok.nextToken();
+ syntax = tok.nextToken();
+ regExp = tok.nextToken();
- try {
- File response = new File(tempFileName);
- FileWriter outWriter = new FileWriter(response);
- Document responseDocument = null;
-
- //System.out.println(store);
+ commandList += command + ",";
- try {
- // convert response Message into Document
- responseDocument =
XMLUtils.convertMessageToDOM(store);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ out.writeBytes("service.mp." + device +
".commands."
+ + command + "=" + realCommand
+ "\n");
+ out.flush();
- OutputFormat format = new
OutputFormat(responseDocument);
+ if (!minParamCount.equalsIgnoreCase("---")) {
+ out.writeBytes("service.mp." + device
+ ".commands."
+ + command +
".minParamCount=" + minParamCount
+ + "\n");
+ out.flush();
+ }
- format.setIndent(4);
- format.setIndenting(true);
- format.setLineSeparator("\n");
+ if (!maxParamCount.equalsIgnoreCase("---")) {
+ out.writeBytes("service.mp." + device
+ ".commands."
+ + command +
".maxParamCount=" + maxParamCount
+ + "\n");
+ out.flush();
+ }
- XMLSerializer serial = new XMLSerializer(outWriter,
format);
- serial.asDOMSerializer();
-
serial.serialize(responseDocument.getDocumentElement());
- serial.setNamespaces(true);
+ if (!cache.equalsIgnoreCase("---")) {
+ out.writeBytes("service.mp." + device
+ ".commands."
+ + command +
".caching=" + cache + "\n");
+ out.flush();
+ }
- outWriter.close();
+ if (!description.equalsIgnoreCase("---")) {
+ out.writeBytes("service.mp." + device
+ ".commands."
+ + command +
".description=" + description
+ + "\n");
+ out.flush();
+ }
- try {
- BufferedReader in = new BufferedReader(new
FileReader(
- tempFileName));
- BufferedWriter out = new BufferedWriter(new
FileWriter(
- outputFileName));
- String str;
- while ((str = in.readLine()) != null) {
+ if (!syntax.equalsIgnoreCase("---")) {
+ out.writeBytes("service.mp." + device
+ ".commands."
+ + command +
".syntax=" + syntax + "\n");
+ out.flush();
+ }
- if (str.contains("<nmwg:store
id=\"store1\">")) {
- String str2 = str
-
.replace("<nmwg:store id=\"store1\">",
-
"<nmwg:store id=\"store1\"
xmlns:nmwg=\"http://ggf.org/ns/nmwg/base/2.0/\">");
- out.write(str2);
- } else if
(str.contains("<nmwgr:datum>")) {
- String str2 = str
-
.replace("<nmwgr:datum>",
-
"<nmwgr:datum xmlns:nmwgr=\"http://ggf.org/ns/nmwg/result/2.0/\">");
- out.write(str2);
-
- } else {
- out.write(str);
- }
-
+ if (!regExp.equalsIgnoreCase("---")) {
+ out.writeBytes("service.mp." + device
+ ".commands."
+ + command + ".regex="
+ regExp + "\n");
+ out.flush();
}
- in.close();
- out.close();
- } catch (IOException e) {
+ input = br.readLine();
}
+ commandList = commandList.substring(0,
commandList.length()-1);
+ out.writeBytes("service.mp." + device + ".commands="
+ + commandList + "\n");
+ out.flush();
- } catch (IOException e) {
- // TODO Auto-generated catch block
+ out.close();
+
+ } catch (FileNotFoundException e) {
e.printStackTrace();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
}
+ inputfile.delete();
+ }
- }
-*/
public static void main(String[] args) {
- if (args.length != 1) {
- System.err.println("Wrong number of arguments!");
- System.exit(0);
- } else {
- System.out.println(args[0]);
- doStuff(args[0]);
- //createServiceStorageXML(args[0], args[0] +
"XML.xml");
+ try {
+ if (args.length != 1) {
+ System.err.println("Wrong number of
arguments!");
+ System.exit(0);
+ } else {
+ //System.out.println(args[0]);
+ ServicePropertiesConfigurator stitcher = new
ServicePropertiesConfigurator();
+ File file = new File(args[0]);
+ stitcher.doStuff(args[0]);
+ //createServiceStorageXML(args[0], args[0] +
"XML.xml");
+ }
+ } catch (RuntimeException e) {
+
}
}
-
}
- perfsonar: r2539 - in branches/SSHTelnet-MP-RELEASE: conf/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters src/org/perfsonar/service/measurementPoint/lookingGlassType/engine/adapters, svnlog, 07/12/2007
Archive powered by MHonArc 2.6.16.