diff --git a/src/im_mad/vmware/OneImVmware.java b/src/im_mad/vmware/OneImVmware.java index ba0816a70f..b88059039b 100644 --- a/src/im_mad/vmware/OneImVmware.java +++ b/src/im_mad/vmware/OneImVmware.java @@ -1,30 +1,36 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2009, Distributed Systems Architecture Group, Universidad */ -/* Complutense de Madrid (dsa-research.org) */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - +/* +# -------------------------------------------------------------------------# +# Copyright 2002-2009, Distributed Systems Architecture Group, Universidad # +# Complutense de Madrid (dsa-research.org) # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------# +*/ import java.io.*; +import java.text.*; +import java.util.*; import com.vmware.vim.*; import com.vmware.apputils.*; import com.vmware.apputils.vim.*; - +/************************************ + * Monitors physical VMware hosts * + * through the VI API * + ************************************/ class OneImVmware extends Thread { @@ -32,21 +38,14 @@ class OneImVmware extends Thread boolean debug; + PrintStream stdout; + PrintStream stderr; // Entry point - main procedure - public static void main(String[] args) { boolean debug_flag; - // first, make redirection - - PrintStream stdout = System.out; - PrintStream stderr = System.err; - - System.setOut(stderr); - System.setErr(stdout); - if (System.getProperty("debug").equals("1")) { debug_flag=true; @@ -55,7 +54,7 @@ class OneImVmware extends Thread { debug_flag=false; } - + OneImVmware oiv = new OneImVmware(args,debug_flag); oiv.loop(); } @@ -64,25 +63,34 @@ class OneImVmware extends Thread OneImVmware(String[] args,boolean _debug) { debug = _debug; - arguments = args; + + // Get out and err descriptors + stdout = System.out; + stderr = System.err; + + // No VMware library output to standard out + // or err. This will be activated when needed + disable_standard_output(); + disable_standard_error(); } - // Main loop, threaded + // Main loop void loop() { - String str = null; - String action = null; - String host; - String hid_str = null; - String hostToMonitor; - boolean fin = false; + String str = null; + String action = null; + String host; + String hid_str = null; + String hostToMonitor; + boolean end = false; - BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); + BufferedReader in = new BufferedReader( + new InputStreamReader(System.in)); - while (!fin) - { + while (!end) + { // Read a line a parse it try { @@ -91,15 +99,12 @@ class OneImVmware extends Thread catch (IOException e) { String message = e.getMessage().replace('\n', ' '); - - synchronized (System.err) - { - System.err.println(action + " FAILURE " + hid_str + " " + message); - } + send_message(action + " FAILURE " + hid_str + " " + message); + send_error (action + " FAILURE " + hid_str + + " Action malformed. Reason: " + message); } - String str_split[] = str.split(" ", 4); - + String str_split[] = str.split(" ", 4); action = str_split[0].toUpperCase(); // Perform the action @@ -110,13 +115,10 @@ class OneImVmware extends Thread else if (action.equals("FINALIZE")) { finalize_mad(); - fin = true; + end = true; } else if (str_split.length != 3) { - synchronized (System.err) - { - System.err.println("FAILURE Unknown command"); - } + send_message("FAILURE Unknown command"); } else { @@ -132,7 +134,8 @@ class OneImVmware extends Thread boolean rf; String response = "HYPERVISOR=vmware"; - String[] argsWithHost = new String[arguments.length+2]; + String[] argsWithHost = + new String[arguments.length+2]; for(int i=0;i # Uncomment the following line to active MAD debug -ONE_MAD_DEBUG=1 +#ONE_MAD_DEBUG=1 # Datastore name VMWARE_DATASTORE=datastore1