diff --git a/cosmic-core/api/src/main/java/com/cloud/host/Status.java b/cosmic-core/api/src/main/java/com/cloud/host/Status.java index be86e3b30f..0813c9feab 100644 --- a/cosmic-core/api/src/main/java/com/cloud/host/Status.java +++ b/cosmic-core/api/src/main/java/com/cloud/host/Status.java @@ -90,11 +90,6 @@ public static String[] toStrings(final Status... states) { return strs; } - public static void main(final String[] args) { - System.out.println("Finite State Machine for Host:"); - System.out.println(s_fsm.toString()); - } - public boolean updateManagementServer() { return updateManagementServer; } diff --git a/cosmic-core/framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java b/cosmic-core/framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java index 6e2214239f..4d01548007 100644 --- a/cosmic-core/framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java +++ b/cosmic-core/framework/db/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeyChanger.java @@ -1,31 +1,19 @@ package com.cloud.utils.crypt; -import com.cloud.utils.PropertiesUtil; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.exception.CloudRuntimeException; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; import java.io.UnsupportedEncodingException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; import java.util.Properties; -import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import org.jasypt.encryption.pbe.config.SimpleStringPBEConfig; -import org.jasypt.exceptions.EncryptionOperationNotPossibleException; -import org.jasypt.properties.EncryptableProperties; /* * EncryptionSecretKeyChanger updates Management Secret Key / DB Secret Key or both. @@ -39,139 +27,6 @@ public class EncryptionSecretKeyChanger { private final StandardPBEStringEncryptor oldEncryptor = new StandardPBEStringEncryptor(); private final StandardPBEStringEncryptor newEncryptor = new StandardPBEStringEncryptor(); - public static void main(final String[] args) { - final List argsList = Arrays.asList(args); - final Iterator iter = argsList.iterator(); - String oldMSKey = null; - String oldDBKey = null; - String newMSKey = null; - String newDBKey = null; - - //Parse command-line args - while (iter.hasNext()) { - final String arg = iter.next(); - // Old MS Key - if (arg.equals("-m")) { - oldMSKey = iter.next(); - } - // Old DB Key - if (arg.equals("-d")) { - oldDBKey = iter.next(); - } - // New MS Key - if (arg.equals("-n")) { - newMSKey = iter.next(); - } - // New DB Key - if (arg.equals("-e")) { - newDBKey = iter.next(); - } - } - - if (oldMSKey == null || oldDBKey == null) { - System.out.println("Existing MS secret key or DB secret key is not provided"); - usage(); - return; - } - - if (newMSKey == null && newDBKey == null) { - System.out.println("New MS secret key and DB secret are both not provided"); - usage(); - return; - } - - final File dbPropsFile = PropertiesUtil.findConfigFile("db.properties"); - final Properties dbProps; - final EncryptionSecretKeyChanger keyChanger = new EncryptionSecretKeyChanger(); - final StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); - keyChanger.initEncryptor(encryptor, oldMSKey); - dbProps = new EncryptableProperties(encryptor); - PropertiesConfiguration backupDBProps = null; - - System.out.println("Parsing db.properties file"); - try (FileInputStream db_prop_fstream = new FileInputStream(dbPropsFile)) { - dbProps.load(db_prop_fstream); - backupDBProps = new PropertiesConfiguration(dbPropsFile); - } catch (final FileNotFoundException e) { - System.out.println("db.properties file not found while reading DB secret key" + e.getMessage()); - } catch (final IOException e) { - System.out.println("Error while reading DB secret key from db.properties" + e.getMessage()); - } catch (final ConfigurationException e) { - e.printStackTrace(); - } - - String dbSecretKey = null; - try { - dbSecretKey = dbProps.getProperty("db.cloud.encrypt.secret"); - } catch (final EncryptionOperationNotPossibleException e) { - System.out.println("Failed to decrypt existing DB secret key from db.properties. " + e.getMessage()); - return; - } - - if (!oldDBKey.equals(dbSecretKey)) { - System.out.println("Incorrect MS Secret Key or DB Secret Key"); - return; - } - - System.out.println("Secret key provided matched the key in db.properties"); - final String encryptionType = dbProps.getProperty("db.cloud.encryption.type"); - - if (newMSKey == null) { - System.out.println("No change in MS Key. Skipping migrating db.properties"); - } else { - if (!keyChanger.migrateProperties(dbPropsFile, dbProps, newMSKey, newDBKey)) { - System.out.println("Failed to update db.properties"); - return; - } else { - //db.properties updated successfully - if (encryptionType.equals("file")) { - //update key file with new MS key - try (FileWriter fwriter = new FileWriter(keyFile); - BufferedWriter bwriter = new BufferedWriter(fwriter)) { - bwriter.write(newMSKey); - } catch (final IOException e) { - System.out.println("Failed to write new secret to file. Please update the file manually"); - } - } - } - } - - boolean success = false; - if (newDBKey == null || newDBKey.equals(oldDBKey)) { - System.out.println("No change in DB Secret Key. Skipping Data Migration"); - } else { - EncryptionSecretKeyChecker.initEncryptorForMigration(oldMSKey); - try { - success = keyChanger.migrateData(oldDBKey, newDBKey); - } catch (final Exception e) { - System.out.println("Error during data migration"); - e.printStackTrace(); - success = false; - } - } - - if (success) { - System.out.println("Successfully updated secret key(s)"); - } else { - System.out.println("Data Migration failed. Reverting db.properties"); - //revert db.properties - try { - backupDBProps.save(); - } catch (final ConfigurationException e) { - e.printStackTrace(); - } - if (encryptionType.equals("file")) { - //revert secret key in file - try (FileWriter fwriter = new FileWriter(keyFile); - BufferedWriter bwriter = new BufferedWriter(fwriter)) { - bwriter.write(oldMSKey); - } catch (final IOException e) { - System.out.println("Failed to revert to old secret to file. Please update the file manually"); - } - } - } - } - private static void usage() { System.out.println("Usage: \tEncryptionSecretKeyChanger \n" + "\t\t-m \n" + "\t\t-d \n" + "\t\t-n [New Mgmt Secret Key] \n" + "\t\t-e [New DB Secret Key]"); diff --git a/cosmic-core/framework/ipc/src/test/java/org/apache/cloudstack/framework/codestyle/AsyncSampleEventDrivenStyleCaller.java b/cosmic-core/framework/ipc/src/test/java/org/apache/cloudstack/framework/codestyle/AsyncSampleEventDrivenStyleCaller.java index 8017958558..c7dd39824b 100644 --- a/cosmic-core/framework/ipc/src/test/java/org/apache/cloudstack/framework/codestyle/AsyncSampleEventDrivenStyleCaller.java +++ b/cosmic-core/framework/ipc/src/test/java/org/apache/cloudstack/framework/codestyle/AsyncSampleEventDrivenStyleCaller.java @@ -19,11 +19,6 @@ public class AsyncSampleEventDrivenStyleCaller { private AsyncSampleCallee _ds; - public static void main(final String[] args) { - final AsyncSampleEventDrivenStyleCaller caller = new AsyncSampleEventDrivenStyleCaller(); - caller.MethodThatWillCallAsyncMethod(); - } - @Test public void MethodThatWillCallAsyncMethod() { final String vol = new String("Hello"); diff --git a/cosmic-core/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/Main.java b/cosmic-core/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/Main.java deleted file mode 100644 index 7ea8476f43..0000000000 --- a/cosmic-core/framework/spring/module/src/main/java/org/apache/cloudstack/spring/module/util/Main.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apache.cloudstack.spring.module.util; - -import org.apache.cloudstack.spring.module.factory.CloudStackSpringContext; - -public class Main { - - long start = System.currentTimeMillis(); - - public Main() { - - } - - public static void main(final String... args) { - final Main main = new Main(); - - try { - main.start(); - System.out.println("STARTUP COMPLETE [" + main.getTime() + "] ms"); - } catch (final Exception e) { - e.printStackTrace(); - System.out.println("STARTUP FAILED [" + main.getTime() + "] ms"); - System.err.println("STARTUP FAILED [" + main.getTime() + "] ms"); - System.exit(1); - } - } - - public void start() throws Exception { - final CloudStackSpringContext context = new CloudStackSpringContext(); - context.registerShutdownHook(); - - if (Boolean.getBoolean("force.exit")) { - System.exit(0); - } - } - - public long getTime() { - return System.currentTimeMillis() - start; - } -} diff --git a/cosmic-core/server/src/main/java/com/cloud/api/doc/ApiXmlDocReader.java b/cosmic-core/server/src/main/java/com/cloud/api/doc/ApiXmlDocReader.java deleted file mode 100644 index 9611788ee0..0000000000 --- a/cosmic-core/server/src/main/java/com/cloud/api/doc/ApiXmlDocReader.java +++ /dev/null @@ -1,274 +0,0 @@ -package com.cloud.api.doc; - -import java.io.BufferedWriter; -import java.io.EOFException; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomDriver; - -public class ApiXmlDocReader { - public static void main(final String[] args) { - String newFile = null; - String oldFile = null; - String dirName = ""; - - final LinkedHashMap commands = new LinkedHashMap<>(); - final LinkedHashMap oldCommands = new LinkedHashMap<>(); - final ArrayList addedCommands = new ArrayList<>(); - final ArrayList removedCommands = new ArrayList<>(); - final HashMap stableCommands = new HashMap<>(); - - final XStream xs = new XStream(new DomDriver()); - xs.alias("command", Command.class); - xs.alias("arg", Argument.class); - - final List argsList = Arrays.asList(args); - final Iterator iter = argsList.iterator(); - while (iter.hasNext()) { - final String arg = iter.next(); - // populate the file names - if (arg.equals("-new")) { - newFile = iter.next(); - } - if (arg.equals("-old")) { - oldFile = iter.next(); - } - if (arg.equals("-d")) { - dirName = iter.next(); - } - } - - try { - try (ObjectInputStream inOld = xs.createObjectInputStream(new FileReader(oldFile))) { - while (true) { - final Command c1 = (Command) inOld.readObject(); - oldCommands.put(c1.getName(), c1); - } - } catch (final EOFException ex) { - // EOF exception shows that there is no more objects in ObjectInputStream, so do nothing here - } - - try (ObjectInputStream inNew = xs.createObjectInputStream(new FileReader(newFile))) { - while (true) { - final Command c = (Command) inNew.readObject(); - commands.put(c.getName(), c); - } - } catch (final EOFException ex) { - // EOF exception shows that there is no more objects in ObjectInputStream, so do nothing here - } - } catch (final Exception ex) { - ex.printStackTrace(); - } - - // Check if any commands got added in new version - for (final Map.Entry entry : commands.entrySet()) { - if (!oldCommands.containsKey(entry.getKey())) { - addedCommands.add(entry.getValue()); - } else { - stableCommands.put(entry.getValue().getName(), entry.getValue()); - } - } - - // Check if any commands were removed in new version - for (final Map.Entry entry : oldCommands.entrySet()) { - if (!commands.containsKey(entry.getKey())) { - removedCommands.add(entry.getValue()); - if (stableCommands.get(entry.getKey()) != null) { - stableCommands.remove(entry.getKey()); - } - } - } - - try (FileWriter fstream = new FileWriter(dirName + "/diff.txt"); - BufferedWriter out = new BufferedWriter(fstream)) { - // Print added commands - out.write("Added commands:\n"); - for (final Command c : addedCommands) { - if (c.getDescription() != null && !c.getDescription().isEmpty()) { - out.write("\n " + c.getName() + " (" + c.getDescription() + ")\n"); - } else { - out.write("\n " + c.getName() + "\n"); - } - } - - // Print removed commands - out.write("\nRemoved commands:\n"); - for (final Command c : removedCommands) { - if (c.getDescription() != null && !c.getDescription().isEmpty()) { - out.write("\n\t" + c.getName() + " (" + c.getDescription() + ")\n"); - } else { - out.write("\n\t" + c.getName() + "\n"); - } - } - - out.write("\nChanges in command type (sync versus async)\n"); - // Verify if the command was sync and became async and vice versa - for (final Map.Entry entry : stableCommands.entrySet()) { - if (commands.get(entry.getKey()).isAsync() != oldCommands.get(entry.getKey()).isAsync()) { - String type = "Sync"; - if (commands.get(entry.getKey()).isAsync()) { - type = "Async"; - } - out.write("\n\t" + entry.getValue().getName() + " became " + type); - } - } - - // Print differences between commands arguments - out.write("\n\nChanges in commands arguments:\n"); - for (final String key : stableCommands.keySet()) { - final ArrayList newReqArgs = new ArrayList<>(); - final ArrayList removedReqArgs = new ArrayList<>(); - final HashMap stableReqArgs = new HashMap<>(); - final ArrayList newRespArgs = new ArrayList<>(); - final ArrayList removedRespArgs = new ArrayList<>(); - - final Command newCommand = commands.get(key); - final Command oldCommand = oldCommands.get(key); - - // Check if any request arguments were added in new version - for (final Argument arg : newCommand.getRequest()) { - if (oldCommand.getReqArgByName(arg.getName()) == null) { - if (!(arg.getName().equals("page") || arg.getName().equals("pagesize") || arg.getName().equals("keyword"))) { - newReqArgs.add(arg); - } - } else { - stableReqArgs.put(arg.getName(), arg); - } - } - - // Check if any request arguments were removed in new version - for (final Argument arg : oldCommand.getRequest()) { - if (newCommand.getReqArgByName(arg.getName()) == null) { - removedReqArgs.add(arg); - if (stableReqArgs.get(arg.getName()) != null) { - stableReqArgs.remove(arg.getName()); - } - } - } - - // Compare stable request arguments of old and new version - for (final Iterator i = stableReqArgs.keySet().iterator(); i.hasNext(); ) { - final String argName = i.next(); - if ((oldCommand.getReqArgByName(argName) != null) && (newCommand.getReqArgByName(argName) != null)) { - if (oldCommand.getReqArgByName(argName).isRequired().equals(newCommand.getReqArgByName(argName).isRequired())) { - i.remove(); - } - } - } - - // Check if any response arguments were added in new version - if (newCommand.getResponse() != null && oldCommand.getResponse() != null) { - for (final Argument arg : newCommand.getResponse()) { - if (oldCommand.getResArgByName(arg.getName()) == null) { - newRespArgs.add(arg); - } - } - - // Check if any response arguments were removed in new version - for (final Argument arg : oldCommand.getResponse()) { - if (newCommand.getResArgByName(arg.getName()) == null) { - removedRespArgs.add(arg); - } - } - } - - if (newReqArgs.size() != 0 || newRespArgs.size() != 0 || removedReqArgs.size() != 0 || removedRespArgs.size() != 0 || stableReqArgs.size() != 0) { - final StringBuffer commandInfo = new StringBuffer(); - commandInfo.append("\n\t" + key); - out.write(commandInfo.toString()); - out.write("\n"); - - // Request - if (newReqArgs.size() != 0 || removedReqArgs.size() != 0 || stableReqArgs.size() != 0) { - final StringBuffer request = new StringBuffer(); - request.append("\n\t\tRequest:\n"); - out.write(request.toString()); - if (newReqArgs.size() != 0) { - final StringBuffer newParameters = new StringBuffer(); - newParameters.append("\n\t\t\tNew parameters: "); - for (final Argument newArg : newReqArgs) { - String isRequiredParam = "optional"; - if (newArg.isRequired()) { - isRequiredParam = "required"; - } - newParameters.append(newArg.getName() + " (" + isRequiredParam + "), "); - } - newParameters.delete(newParameters.length() - 2, newParameters.length() - 1); - out.write(newParameters.toString()); - out.write("\n"); - } - if (removedReqArgs.size() != 0) { - final StringBuffer removedParameters = new StringBuffer(); - removedParameters.append("\n\t\t\tRemoved parameters: "); - for (final Argument removedArg : removedReqArgs) { - removedParameters.append(removedArg.getName() + ", "); - } - removedParameters.delete(removedParameters.length() - 2, removedParameters.length() - 1); - out.write(removedParameters.toString()); - out.write("\n"); - } - - if (stableReqArgs.size() != 0) { - final StringBuffer changedParameters = new StringBuffer(); - changedParameters.append("\n\t\t\tChanged parameters: "); - for (final Argument stableArg : stableReqArgs.values()) { - String newRequired = "optional"; - String oldRequired = "optional"; - if ((oldCommand.getReqArgByName(stableArg.getName()) != null) && (oldCommand.getReqArgByName(stableArg.getName()).isRequired() == true)) { - oldRequired = "required"; - } - if ((newCommand.getReqArgByName(stableArg.getName()) != null) && (newCommand.getReqArgByName(stableArg.getName()).isRequired() == true)) { - newRequired = "required"; - } - changedParameters.append(stableArg.getName() + " (old version - " + oldRequired + ", new version - " + newRequired + "), "); - } - changedParameters.delete(changedParameters.length() - 2, changedParameters.length() - 1); - out.write(changedParameters.toString()); - out.write("\n"); - } - } - - // Response - if (newRespArgs.size() != 0 || removedRespArgs.size() != 0) { - final StringBuffer changedResponseParams = new StringBuffer(); - changedResponseParams.append("\n\t\tResponse:\n"); - out.write(changedResponseParams.toString()); - if (newRespArgs.size() != 0) { - final StringBuffer newRespParams = new StringBuffer(); - newRespParams.append("\n\t\t\tNew parameters: "); - for (final Argument newArg : newRespArgs) { - newRespParams.append(newArg.getName() + ", "); - } - newRespParams.delete(newRespParams.length() - 2, newRespParams.length() - 1); - out.write(newRespParams.toString()); - out.write("\n"); - } - if (removedRespArgs.size() != 0) { - final StringBuffer removedRespParams = new StringBuffer(); - removedRespParams.append("\n\t\t\tRemoved parameters: "); - for (final Argument removedArg : removedRespArgs) { - removedRespParams.append(removedArg.getName() + ", "); - } - removedRespParams.delete(removedRespParams.length() - 2, removedRespParams.length() - 1); - out.write(removedRespParams.toString()); - out.write("\n"); - } - } - } - } - } catch (final IOException e) { - e.printStackTrace(); - } - } -} diff --git a/cosmic-core/server/src/main/java/com/cloud/test/DatabaseConfig.java b/cosmic-core/server/src/main/java/com/cloud/test/DatabaseConfig.java index 26aa0d144e..1aa9cd591b 100644 --- a/cosmic-core/server/src/main/java/com/cloud/test/DatabaseConfig.java +++ b/cosmic-core/server/src/main/java/com/cloud/test/DatabaseConfig.java @@ -6,7 +6,6 @@ import com.cloud.storage.DiskOfferingVO; import com.cloud.storage.Storage.ProvisioningType; import com.cloud.storage.dao.DiskOfferingDaoImpl; -import com.cloud.utils.PropertiesUtil; import com.cloud.utils.component.ComponentContext; import com.cloud.utils.db.DB; import com.cloud.utils.db.Transaction; @@ -37,7 +36,6 @@ import java.util.Map; import java.util.UUID; -import org.apache.log4j.xml.DOMConfigurator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -350,37 +348,6 @@ public DatabaseConfig(final String configFileName) { _configFileName = configFileName; } - /** - * @param args - name of server-setup.xml file which contains the bootstrap data - */ - public static void main(final String[] args) { - System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"); - System.setProperty("javax.xml.parsers.SAXParserFactory", "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"); - - final File file = PropertiesUtil.findConfigFile("log4j-cloud.xml"); - if (file != null) { - System.out.println("Log4j configuration from : " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); - } else { - System.out.println("Configure log4j with default properties"); - } - - if (args.length < 1) { - s_logger.error("error starting database config, missing initial data file"); - } else { - try { - final DatabaseConfig config = ComponentContext.inject(DatabaseConfig.class); - config.doVersionCheck(); - config.doConfig(); - System.exit(0); - } catch (final Exception ex) { - System.out.print("Error Caught"); - ex.printStackTrace(); - s_logger.error("error", ex); - } - } - } - private void doVersionCheck() { try { final String warningMsg = "\nYou are using an outdated format for server-setup.xml. Please switch to the new format.\n"; diff --git a/cosmic-core/server/src/main/java/com/cloud/test/IPRangeConfig.java b/cosmic-core/server/src/main/java/com/cloud/test/IPRangeConfig.java index e3c3f8e98f..3d3799fd54 100644 --- a/cosmic-core/server/src/main/java/com/cloud/test/IPRangeConfig.java +++ b/cosmic-core/server/src/main/java/com/cloud/test/IPRangeConfig.java @@ -1,6 +1,5 @@ package com.cloud.test; -import com.cloud.utils.component.ComponentContext; import com.cloud.utils.db.DB; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.net.NetUtils; @@ -16,13 +15,6 @@ import java.util.Vector; public class IPRangeConfig { - - public static void main(final String[] args) { - final IPRangeConfig config = ComponentContext.inject(IPRangeConfig.class); - config.run(args); - System.exit(0); - } - public void run(final String[] args) { if (args.length < 2) { printError(usage()); diff --git a/cosmic-core/server/src/main/java/com/cloud/test/PodZoneConfig.java b/cosmic-core/server/src/main/java/com/cloud/test/PodZoneConfig.java index 7ee79a508a..d202aaf349 100644 --- a/cosmic-core/server/src/main/java/com/cloud/test/PodZoneConfig.java +++ b/cosmic-core/server/src/main/java/com/cloud/test/PodZoneConfig.java @@ -1,7 +1,6 @@ package com.cloud.test; import com.cloud.network.Networks.TrafficType; -import com.cloud.utils.component.ComponentContext; import com.cloud.utils.db.DB; import com.cloud.utils.db.TransactionLegacy; import com.cloud.utils.net.NetUtils; @@ -15,13 +14,6 @@ import java.util.Vector; public class PodZoneConfig { - - public static void main(final String[] args) { - final PodZoneConfig config = ComponentContext.inject(PodZoneConfig.class); - //config.run(args); - System.exit(0); - } - public static long getPodId(final String pod, final long dcId) { final String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\""; final String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support."; diff --git a/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java b/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java index a66a055783..59ab76f911 100644 --- a/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java +++ b/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java @@ -307,31 +307,6 @@ private static void startupHttpCmdPort() { } } - public static void main(final String[] argv) { - standaloneStart = true; - configLog4j(); - Logger.setFactory(new ConsoleProxyLoggerFactory()); - - final InputStream confs = ConsoleProxy.class.getResourceAsStream("/conf/consoleproxy.properties"); - final Properties conf = new Properties(); - if (confs == null) { - s_logger.info("Can't load consoleproxy.properties from classpath, will use default configuration"); - } else { - try { - conf.load(confs); - } catch (final Exception e) { - s_logger.error(e.toString(), e); - } finally { - try { - confs.close(); - } catch (final IOException ioex) { - s_logger.error(ioex.toString(), ioex); - } - } - } - start(conf); - } - public static ConsoleProxyClient getVncViewer(final ConsoleProxyClientParam param) throws Exception { ConsoleProxyClient viewer = null; diff --git a/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxyMonitor.java b/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxyMonitor.java deleted file mode 100644 index fce10bc41c..0000000000 --- a/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/ConsoleProxyMonitor.java +++ /dev/null @@ -1,143 +0,0 @@ -package com.cloud.consoleproxy; - -import com.cloud.consoleproxy.util.Logger; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import org.apache.log4j.xml.DOMConfigurator; - -// -// -// I switched to a simpler solution to monitor only unrecoverable exceptions, under these cases, console proxy process will exit -// itself and the shell script will re-launch console proxy -// -public class ConsoleProxyMonitor { - private static final Logger s_logger = Logger.getLogger(ConsoleProxyMonitor.class); - - private final String[] _argv; - private final Map _argMap = new HashMap<>(); - - private volatile Process _process; - private boolean _quit = false; - - public ConsoleProxyMonitor(final String[] argv) { - _argv = argv; - - for (final String arg : _argv) { - final String[] tokens = arg.split("="); - if (tokens.length == 2) { - s_logger.info("Add argument " + tokens[0] + "=" + tokens[1] + " to the argument map"); - - _argMap.put(tokens[0].trim(), tokens[1].trim()); - } else { - s_logger.warn("unrecognized argument, skip adding it to argument map"); - } - } - } - - public static void main(final String[] argv) { - configLog4j(); - (new ConsoleProxyMonitor(argv)).run(); - } - - private static void configLog4j() { - URL configUrl = System.class.getResource("/conf/log4j-cloud.xml"); - if (configUrl == null) { - configUrl = ClassLoader.getSystemResource("log4j-cloud.xml"); - } - - if (configUrl == null) { - configUrl = ClassLoader.getSystemResource("conf/log4j-cloud.xml"); - } - - if (configUrl != null) { - try { - System.out.println("Configure log4j using " + configUrl.toURI().toString()); - } catch (final URISyntaxException e1) { - e1.printStackTrace(); - } - - try { - final File file = new File(configUrl.toURI()); - - System.out.println("Log4j configuration from : " + file.getAbsolutePath()); - DOMConfigurator.configureAndWatch(file.getAbsolutePath(), 10000); - } catch (final URISyntaxException e) { - System.out.println("Unable to convert log4j configuration Url to URI"); - } - } else { - System.out.println("Configure log4j with default properties"); - } - } - - private void run() { - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - _quit = true; - onShutdown(); - } - }); - - while (!_quit) { - final String cmdLine = getLaunchCommandLine(); - - s_logger.info("Launch console proxy process with command line: " + cmdLine); - - try { - _process = Runtime.getRuntime().exec(cmdLine); - } catch (final IOException e) { - s_logger.error("Unexpected exception ", e); - System.exit(1); - } - - boolean waitSucceeded = false; - int exitCode = 0; - while (!waitSucceeded) { - try { - exitCode = _process.waitFor(); - waitSucceeded = true; - - if (s_logger.isInfoEnabled()) { - s_logger.info("Console proxy process exits with code: " + exitCode); - } - } catch (final InterruptedException e) { - if (s_logger.isInfoEnabled()) { - s_logger.info("InterruptedException while waiting for termination of console proxy, will retry"); - } - } - } - } - } - - private void onShutdown() { - if (_process != null) { - if (s_logger.isInfoEnabled()) { - s_logger.info("Console proxy monitor shuts dwon, terminate console proxy process"); - } - _process.destroy(); - } - } - - private String getLaunchCommandLine() { - final StringBuffer sb = new StringBuffer("java "); - final String jvmOptions = _argMap.get("jvmoptions"); - - if (jvmOptions != null) { - sb.append(jvmOptions); - } - - for (final Map.Entry entry : _argMap.entrySet()) { - if (!"jvmoptions".equalsIgnoreCase(entry.getKey())) { - sb.append(" ").append(entry.getKey()).append("=").append(entry.getValue()); - } - } - - return sb.toString(); - } -} diff --git a/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/vnc/VncClient.java b/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/vnc/VncClient.java index 0d15f60b37..73427aba6b 100644 --- a/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/vnc/VncClient.java +++ b/cosmic-core/services/console-proxy-server/src/main/java/com/cloud/consoleproxy/vnc/VncClient.java @@ -363,34 +363,6 @@ private static byte flipByte(final byte b) { return c; } - public static void main(final String[] args) { - if (args.length < 3) { - printHelpMessage(); - System.exit(1); - } - - final String host = args[0]; - final String port = args[1]; - final String password = args[2]; - - try { - new VncClient(host, Integer.parseInt(port), password, false, null); - } catch (final NumberFormatException e) { - s_logger.error("Incorrect VNC server port number: " + port + "."); - System.exit(1); - } catch (final UnknownHostException e) { - s_logger.error("Incorrect VNC server host name: " + host + "."); - System.exit(1); - } catch (final IOException e) { - s_logger.error("Cannot communicate with VNC server: " + e.getMessage()); - System.exit(1); - } catch (final Throwable e) { - s_logger.error("An error happened: " + e.getMessage()); - System.exit(1); - } - System.exit(0); - } - private static void printHelpMessage() { /* LOG */ s_logger.info("Usage: HOST PORT PASSWORD."); diff --git a/cosmic-core/utils/src/main/java/com/cloud/maint/Version.java b/cosmic-core/utils/src/main/java/com/cloud/maint/Version.java index c37882b936..4d44a2b52d 100644 --- a/cosmic-core/utils/src/main/java/com/cloud/maint/Version.java +++ b/cosmic-core/utils/src/main/java/com/cloud/maint/Version.java @@ -24,10 +24,6 @@ public static String trimRouterVersion(final String version) { return "0"; } - public static void main(final String[] args) { - System.out.println("Result is " + compare(args[0], args[1])); - } - /** * Compares two version strings and see which one is higher version. * diff --git a/cosmic-core/utils/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeySender.java b/cosmic-core/utils/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeySender.java deleted file mode 100644 index 2709cb4b95..0000000000 --- a/cosmic-core/utils/src/main/java/com/cloud/utils/crypt/EncryptionSecretKeySender.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.cloud.utils.crypt; - -import com.cloud.utils.NumbersUtil; - -import java.io.PrintWriter; -import java.net.InetAddress; -import java.net.Socket; - -public class EncryptionSecretKeySender { - public static void main(final String[] args) { - try { - // Create a socket to the host - String hostname = "localhost"; - int port = 8097; - - if (args.length == 2) { - hostname = args[0]; - port = NumbersUtil.parseInt(args[1], port); - } - final InetAddress addr = InetAddress.getByName(hostname); - try (Socket socket = new Socket(addr, port); - PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) { - final java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - final String validationWord = "cloudnine"; - String validationInput = ""; - while (!validationWord.equals(validationInput)) { - System.out.print("Enter Validation Word:"); - validationInput = stdin.readLine(); - System.out.println(); - } - System.out.print("Enter Secret Key:"); - final String input = stdin.readLine(); - if (input != null) { - out.println(input); - } - } catch (final Exception e) { - System.out.println("Exception " + e.getMessage()); - } - } catch (final Exception e) { - System.out.print("Exception while sending secret key " + e); - } - } -} diff --git a/cosmic-core/utils/src/main/java/com/cloud/utils/net/MacAddress.java b/cosmic-core/utils/src/main/java/com/cloud/utils/net/MacAddress.java index 601f5cb99f..c61de16bce 100644 --- a/cosmic-core/utils/src/main/java/com/cloud/utils/net/MacAddress.java +++ b/cosmic-core/utils/src/main/java/com/cloud/utils/net/MacAddress.java @@ -2,8 +2,6 @@ import static com.cloud.utils.AutoCloseableUtil.closeAutoCloseable; -import com.cloud.utils.NumbersUtil; - import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -182,13 +180,6 @@ static String parse(String in) { return null; } - public static void main(final String[] args) { - final MacAddress addr = MacAddress.getMacAddress(); - System.out.println("addr in integer is " + addr.toLong()); - System.out.println("addr in bytes is " + NumbersUtil.bytesToString(addr.toByteArray(), 0, addr.toByteArray().length)); - System.out.println("addr in char is " + addr.toString(":")); - } - public static MacAddress getMacAddress() { return s_address; } diff --git a/cosmic-core/utils/src/test/java/com/cloud/utils/DateUtilTest.java b/cosmic-core/utils/src/test/java/com/cloud/utils/DateUtilTest.java deleted file mode 100644 index f6e1e31e88..0000000000 --- a/cosmic-core/utils/src/test/java/com/cloud/utils/DateUtilTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.cloud.utils; - -import com.cloud.utils.DateUtil.IntervalType; - -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; - -public class DateUtilTest { - - // command line test tool - public static void main(final String[] args) { - final TimeZone localTimezone = Calendar.getInstance().getTimeZone(); - final TimeZone gmtTimezone = TimeZone.getTimeZone("GMT"); - final TimeZone estTimezone = TimeZone.getTimeZone("EST"); - - Date time = new Date(); - System.out.println("local time :" + DateUtil.getDateDisplayString(localTimezone, time)); - System.out.println("GMT time :" + DateUtil.getDateDisplayString(gmtTimezone, time)); - System.out.println("EST time :" + DateUtil.getDateDisplayString(estTimezone, time)); - //Test next run time. Expects interval and schedule as arguments - if (args.length == 2) { - System.out.println("Next run time: " + DateUtil.getNextRunTime(IntervalType.getIntervalType(args[0]), args[1], "GMT", time).toString()); - } - - time = new Date(); - final DateFormat dfDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'Z"); - final String str = dfDate.format(time); - System.out.println("Formated TZ time string : " + str); - try { - final Date dtParsed = DateUtil.parseTZDateString(str); - System.out.println("Parsed TZ time string : " + dtParsed.toString()); - } catch (final ParseException e) { - System.err.println("Parsing failed\n string : " + str + "\nexception :" + e.getLocalizedMessage()); - } - } -}