Cleaning up code for runtime, installer, RMI, compiler for the Java side
[iot2.git] / iotjava / iotruntime / master / IoTMaster.java
index 03a365227e43a7d9381739d78f6a5815fc6c70e1..70ae6b876c9e8cd849b266a2a5032cf6dd2753ae 100644 (file)
@@ -140,8 +140,8 @@ public final class IoTMaster {
        private static final String STR_SHELL_HEADER = "#!/bin/sh";
        private static final String STR_JAVA_PATH = "/usr/bin/java";
        private static final String STR_MAC_POL_PATH = "tomoyo/";
-        private static final String STR_TMP = "tmp";
-        private static final String STR_ARP = "arp";
+       private static final String STR_TMP = "tmp";
+       private static final String STR_ARP = "arp";
 
        private static int INT_SIZE = 4;        // send length in the size of integer (4 bytes)
        private static final int INT_DNS_PORT = 53;
@@ -229,7 +229,6 @@ public final class IoTMaster {
                else
                        throw new Error("IoTMaster: Unknown value for STR_MAC_TO_IP_TRANSLATION: " + STR_MAC_TO_IP_TRANSLATION);
                processJailConfig = new ProcessJailConfig();
-               //processJailConfig.setAddressListObject(routerConfig.getAddressListObject());
                objInitHand = new ObjectInitHandler(BOOL_VERBOSE);
                objAddInitHand = new ObjectAddressInitHandler(BOOL_VERBOSE);
                mapClassNameToCrim = new HashMap<String,Object>();
@@ -346,9 +345,9 @@ public final class IoTMaster {
                        System.out.println("IoTMaster: Error reading config file: " + strCfgFileName);
                        ex.printStackTrace();
                }
-               System.out.println("IoTMaster: Reading " + strCfgField +
+               RuntimeOutput.print("IoTMaster: Reading " + strCfgField +
                        " from config file: " + strCfgFileName + " with value: " + 
-                       prop.getProperty(strCfgField, null));
+                       prop.getProperty(strCfgField, null), BOOL_VERBOSE);
                // NULL is returned if the property isn't found
                return prop.getProperty(strCfgField, null);
        }
@@ -423,7 +422,7 @@ public final class IoTMaster {
         * @params  strFieldName              String field name
         * @params  strIoTSlaveObjectHostAdd  String slave host address
         * @params  inStream                  ObjectInputStream communication
-        * @params  inStream                  ObjectOutputStream communication
+        * @params  outStream                 ObjectOutputStream communication
         * @params  strLanguage                           String language
         * @return  void
         */
@@ -468,12 +467,6 @@ public final class IoTMaster {
                        if (commHan.getComPort(strDeviceAddressKey) == null) {
                                commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
                        }
-
-                       // TODO: DEBUG!!!
-                       System.out.println("\n\n DEBUG: InstrumentSetDevice: Object Name: " + strObjName);
-                       System.out.println("DEBUG: InstrumentSetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
-                       System.out.println("DEBUG: InstrumentSetDevice: Device address: " + strDeviceAddressKey + "\n\n");
-
                        // Send address one by one
                        if(strLanguage.equals(STR_JAVA)) {
                                Message msgGetIoTSetObj = null;
@@ -534,12 +527,6 @@ public final class IoTMaster {
                }               
                int iRows = setInstrumenter.numberOfRows();
                RuntimeOutput.print("IoTMaster: Number of rows for IoTZigbeeAddress: " + iRows, BOOL_VERBOSE);
-
-               // TODO: DEBUG!!!
-               System.out.println("\n\nDEBUG: InstrumentZigbeeDevice: Object Name: " + strObjName);
-               System.out.println("DEBUG: InstrumentZigbeeDevice: Port number: " + commHan.getComPort(strZigbeeGWAddressKey));
-               System.out.println("DEBUG: InstrumentZigbeeDevice: Device address: " + strZigbeeGWAddress + "\n\n");
-
                // Transfer the address
                for(int iRow=0; iRow<iRows; iRow++) {
                        arrFieldValues = setInstrumenter.fieldValues(iRow);
@@ -614,7 +601,6 @@ public final class IoTMaster {
 
                // Extract the interface name for RMI
                // e.g. ProximitySensorInterface, TempSensorInterface, etc.
-               
                String strObjCfgFile = STR_IOT_CODE_PATH + strObjClassName + "/" + strObjClassName + STR_CFG_FILE_EXT;
                strObjClassInterfaceName = parseConfigFile(strObjCfgFile, STR_INTERFACE_CLS_CFG);
                strObjStubClsIntfaceName = parseConfigFile(strObjCfgFile, STR_INT_STUB_CLS_CFG);
@@ -629,7 +615,6 @@ public final class IoTMaster {
                } else {
                        // If this is a new object ... then create one
                        // Get host address for IoTSlave from LoadBalancer
-                       //strIoTSlaveObjectHostAdd = lbIoT.selectHost();
                        strIoTSlaveObjectHostAdd = routerConfig.getIPFromMACAddress(lbIoT.selectHost());
                        if (strIoTSlaveControllerHostAdd == null)
                                throw new Error("IoTMaster: Could not translate MAC to IP address! Please check the router's /tmp/dhcp.leases!");
@@ -656,7 +641,6 @@ public final class IoTMaster {
                        routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveControllerHostAdd,
                                strIoTSlaveObjectHostAdd, STR_TCP_PROTOCOL);
                        // Configure MAC policies for objects
-                       //String strFileName = STR_MAC_POL_PATH + strObjClassName + STR_MAC_POLICY_EXT;
                        String strFileName = STR_MAC_POL_PATH + STR_JAVA + STR_MAC_POLICY_EXT;
                        if (STR_ACTIVATE_SANDBOXING.equals("Yes")) {
                                processJailConfig.configureProcessJailDeviceDriverPolicies(strIoTSlaveObjectHostAdd, strObjName, strObjClassName,
@@ -735,12 +719,6 @@ public final class IoTMaster {
                                        commHan.addAdditionalPort(strUniqueDev);
                                }
                        }
-
-                       // TODO: DEBUG!!!
-                       System.out.println("\n\n DEBUG: InstrumentPolicySetDevice: Object Name: " + strObjName);
-                       System.out.println("DEBUG: InstrumentPolicySetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
-                       System.out.println("DEBUG: InstrumentPolicySetDevice: Device address: " + strDeviceAddressKey + "\n\n");
-
                        // Send routing policy to router for device drivers and devices
                        // ROUTING POLICY: RMI communication - RMI registry and stub ports
                        if((iDestDeviceDriverPort == -1) && (!strProtocol.equals(STR_NO_PROTOCOL))) {
@@ -963,7 +941,7 @@ public final class IoTMaster {
                // Send the file to the compute node
                String strCmdSend = "scp " + shellFile + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + ":" + STR_RUNTIME_DIR;
                runCommand(strCmdSend);
-               System.out.println("IoTMaster: Sending shell file: " + strCmdSend);
+               RuntimeOutput.print("IoTMaster: Sending shell file: " + strCmdSend, BOOL_VERBOSE);
                return STR_SSH + " " + STR_USERNAME + strIoTSlaveObjectHostAdd + " cd " + STR_RUNTIME_DIR + " " + shellFile;
        }
 
@@ -1020,12 +998,6 @@ public final class IoTMaster {
                        strLanguageDriver = parseConfigFile(sCfgFile, STR_LANGUAGE);
                if(strLanguageDriver == null) // Check nullness for the second time - report if it is still null
                        throw new Error("IoTMaster: Language specification missing in config file: " + sCfgFile);
-               // PROFILING
-               long start = 0;
-               long result = 0;
-               // PROFILING
-               start = System.currentTimeMillis();
-
                // Construct ssh command line
                // e.g. ssh rtrimana@dw-2.eecs.uci.edu cd <path>;
                //      java -cp $CLASSPATH:./*.jar
@@ -1040,7 +1012,6 @@ public final class IoTMaster {
                else
                        throw new Error("IoTMaster: Language specification not recognized: " + strLanguageDriver);
                RuntimeOutput.print("IoTMaster: Language for " + strObjName + " is " + strLanguageDriver, BOOL_VERBOSE);
-
                RuntimeOutput.print(strSSHCommand, BOOL_VERBOSE);
                // Start a new thread to start a new JVM
                createThread(strSSHCommand);
@@ -1058,14 +1029,6 @@ public final class IoTMaster {
                        outStream = new BufferedOutputStream(socket.getOutputStream());
                        recvAck(inStream);
                }
-
-               // PROFILING
-               result = System.currentTimeMillis()-start;
-               System.out.println("\n\n ==> Time needed to start JVM for " + strObjName + ": " + result + "\n\n");
-
-               // PROFILING
-               start = System.currentTimeMillis();
-
                if(strLanguageDriver.equals(STR_JAVA)) {
                        sendFileToJavaSlaveDriver(serverSocket, inStream, outStream, strObjName, 
                                strObjClassName, strObjClassInterfaceName, strObjStubClsIntfaceName,
@@ -1076,14 +1039,6 @@ public final class IoTMaster {
                        commHan.getRMIRegPort(strObjName), commHan.getRMIStubPort(strObjName), arrFieldValues, arrFieldClasses,
                        outStream, inStream);
                }
-
-               // PROFILING
-               result = System.currentTimeMillis()-start;
-               System.out.println("\n\n ==> Time needed to send JAR file for " + strObjName + ": " + result + "\n\n");
-
-               // PROFILING
-               start = System.currentTimeMillis();
-
                // Instrument the class source code and look for IoTSet for device addresses
                // e.g. @config private IoTSet<IoTDeviceAddress> lb_addresses;
                RuntimeOutput.print("IoTMaster: Instantiating for " + strObjClassName + " with objectID " + strFieldObjectID, BOOL_VERBOSE);
@@ -1141,11 +1096,6 @@ public final class IoTMaster {
                        createDriverObjectCpp(outStream, inStream);
                        //endSessionCpp(outStream);
                }
-
-               // PROFILING
-               result = System.currentTimeMillis()-start;
-               System.out.println("\n\n ==> Time needed to create object " + strObjName + " and instrument IoTDeviceAddress: " + result + "\n\n");
-
                // Closing streams
                outStream.close();
                inStream.close();
@@ -1369,7 +1319,6 @@ public final class IoTMaster {
                                reinitializeIoTSetFieldCpp(outStream, inStream);
                        } else if (iotcommMsg == IoTCommCode.CREATE_NEW_IOTRELATION) {
                                // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO CREATE IOTRELATION
-                               // TODO: createNewIoTRelation needs to be created here!
                                createNewIoTRelationCpp(str, outStream, inStream);
                                List<ObjectInitInfo> listObject = objInitHand.getListObjectInitInfo(str);
                                List<ObjectInitInfo> listSecondObject = objInitHand.getSecondObjectInitInfo(str);
@@ -2075,13 +2024,6 @@ public final class IoTMaster {
                                        recvAck(inStream);
                                }
                                RuntimeOutput.print("IoTMaster: Communication established!", BOOL_VERBOSE);
-
-                               // PROFILING
-                               result = System.currentTimeMillis()-start;
-                               System.out.println("\n\n ==> From start until after SSH for main controller: " + result);
-                               // PROFILING
-                               start = System.currentTimeMillis();
-
                                // Send files for every controller class
                                // e.g. AcmeProximity.jar and AcmeProximity.zip
                                String strControllerClassName = strObjControllerName + STR_CLS_FILE_EXT;
@@ -2112,13 +2054,6 @@ public final class IoTMaster {
                                        processJailConfig.combineAdditionalMACPolicy(strContMACCfg, strObjControllerName, strObjControllerName);
                                    }
                                }
-                               // PROFILING
-                               result = System.currentTimeMillis()-start;
-                               System.out.println("\n\n ==> From IoTSlave start until main controller object is created: " + result);
-                               System.out.println(" ==> Including file transfer times!\n\n");
-                               // PROFILING
-                               start = System.currentTimeMillis();
-
                                // == END INITIALIZING CONTROLLER/DEVICE IOTSLAVE ==
                                // Instrumenting one file
                                RuntimeOutput.print("IoTMaster: Opening class file: " + strControllerClassName, BOOL_VERBOSE);
@@ -2146,11 +2081,6 @@ public final class IoTMaster {
                                        // SetInstrumenter vs. RelationInstrumenter
                                        String strFieldName = map.getKey();
                                        String strClassName = map.getValue().getClass().getName();
-
-                           System.out.println("\n\nDEBUG: Instrumenting IoTSet and IoTRelation objects!!!");
-                           System.out.println("DEBUG: Field name: " + strFieldName);
-                           System.out.println("DEBUG: Class name: " + strFieldName + "\n\n");
-
                                        if(strClassName.equals(STR_SET_INSTRUMENTER_CLS)) {
                                                SetInstrumenter setInstrumenter = (SetInstrumenter) map.getValue();
                                                if(setInstrumenter.getObjTableName().equals(STR_IOT_DEV_ADD_CLS)) { 
@@ -2177,15 +2107,6 @@ public final class IoTMaster {
                                String strTempFileName = "./" + strObjControllerName + STR_MAC_POLICY_EXT;
                                processJailConfig.combineControllerMACPolicies(strIoTSlaveControllerHostAdd, strObjControllerName, strTempFileName);
                                processJailConfig.flush();
-
-                               // PROFILING
-                               result = System.currentTimeMillis()-start;
-                               System.out.println("\n\n ==> Time needed to instrument device driver objects: " + result + "\n\n");
-                               System.out.println(" ==> #Objects: " + commHan.getActiveControllerObjectList().size() + "\n\n");
-
-                               // PROFILING
-                               start = System.currentTimeMillis();
-
                                // ROUTING POLICY: implement basic policies to reject all other irrelevant traffics
                                for(String s: commHan.getHosts()) {
                                        setHostBasicPolicies(s);
@@ -2200,33 +2121,13 @@ public final class IoTMaster {
                                // See if firewall policy is configured to be "on" or "off"
                                if (STR_POLICY_ON.equals(STR_YES))
                                        createPolicyThreads(STR_ROUTER_ADD, setAddresses);
-
-                               // PROFILING
-                               result = System.currentTimeMillis()-start;
-                               System.out.println("\n\n ==> Time needed to send policy files and deploy them : " + result + "\n\n");
-
-                               // PROFILING
-                               start = System.currentTimeMillis();
-
                                // Separating object creations and Set/Relation initializations
                                createDriverObjects();
-
-                               // PROFILING
-                               result = System.currentTimeMillis()-start;
-                               System.out.println("\n\n ==> Time needed to instantiate objects: " + result + "\n\n");
-                               // PROFILING
-                               start = System.currentTimeMillis();
-
                                // Sets and relations initializations
                                if(STR_LANGUAGE_CONTROLLER.equals(STR_JAVA))
                                        initializeSetsAndRelationsJava(inStream, outStream);
                                else
                                        initializeSetsAndRelationsCpp(inStream, outStream);;
-
-                               // PROFILING
-                               result = System.currentTimeMillis()-start;
-                               System.out.println("\n\n ==> Time needed to initialize sets and relations: " + result + "\n\n");
-
                                if(STR_LANGUAGE_CONTROLLER.equals(STR_JAVA))
                                        // == COMMUNICATION WITH IOTSLAVE CONTROLLER TO EXECUTE INIT METHOD
                                        commMasterToSlave(new MessageSimple(IoTCommCode.INVOKE_INIT_METHOD), "Invoke init() method!", inStream, outStream);