MRFramework/src/main/java/com/mr/util/CreateInstances.java
/**
	 * Run commands specific to instance number. 0 stands for master and rest
	 * are slave.
	 */
Run commands specific to instance number. 0 stands for master and rest
are slave.
Run commands specific to instance number . 0 stands for master and rest are slave .
private static void runJarInInstances() {
		try {
			log.info("Running Jar on all EC2 instances");
			String user = "ec2-user";
			int port = 22;
			String privateKey = pemKeysPath+pemKeys+".pem";
			String command = "";
			for (Map.Entry<Integer, String> entry : mapOfInstances.entrySet()) {
				JSch jsch = new JSch();
				String host = entry.getValue();
				jsch.addIdentity(privateKey);
				Session session = jsch.getSession(user, host, port);
				log.info("session created.");
				java.util.Properties config = new java.util.Properties();
				config.put("StrictHostKeyChecking", "no");
				session.setConfig(config);
				session.connect();
				Channel channel = session.openChannel("shell");
				if (entry.getKey() == 0)
					command = "cd /tmp \n ls \n java -Dtype=\"master\" -jar "+jarPath+" master &\n ";
				else
					command = "cd /tmp \n ls \n java -Dtype=\"slave\" -Did=\""+entry.getKey()+"\" -jar "+jarPath+" &\n";
				InputStream in = new ByteArrayInputStream(command.getBytes(StandardCharsets.UTF_8));
				channel.setInputStream(in);
				channel.setOutputStream(System.out);
				channel.connect(10 * 1000);
				if(entry.getKey() == 0) {
					Thread.sleep(5000);
				}
			}
		} catch (Exception e) {
			log.error(e.getMessage());
		}
	}
private static void runJarInInstances ( ) { try { log . info ( "Running Jar on all EC2 instances" ) ; String user = "ec2-user" ; int port = 22 ; String privateKey = pemKeysPath + pemKeys + ".pem" ; String command = "" ; for ( Map . Entry < Integer , String > entry : mapOfInstances . entrySet ( ) ) { JSch jsch = new JSch ( ) ; String host = entry . getValue ( ) ; jsch . addIdentity ( privateKey ) ; Session session = jsch . getSession ( user , host , port ) ; log . info ( "session created." ) ; java . util . Properties config = new java . util . Properties ( ) ; config . put ( "StrictHostKeyChecking" , "no" ) ; session . setConfig ( config ) ; session . connect ( ) ; Channel channel = session . openChannel ( "shell" ) ; if ( entry . getKey ( ) == 0 ) command = "cd /tmp \n ls \n java -Dtype=\"master\" -jar " + jarPath + " master &\n " ; else command = "cd /tmp \n ls \n java -Dtype=\"slave\" -Did=\"" + entry . getKey ( ) + "\" -jar " + jarPath + " &\n" ; InputStream in = new ByteArrayInputStream ( command . getBytes ( StandardCharsets . UTF_8 ) ) ; channel . setInputStream ( in ) ; channel . setOutputStream ( System . out ) ; channel . connect ( 10 * 1000 ) ; if ( entry . getKey ( ) == 0 ) { Thread . sleep ( 5000 ) ; } } } catch ( Exception e ) { log . error ( e . getMessage ( ) ) ; } }
Run commands specific to instance number.
Run commands specific to instance number .