MRFramework/src/main/java/com/mr/util/CreateInstances.java
/**
	 * Write all instance data into a file
	 * 
	 * @return File, containing instance data
	 * @throws IOException
	 */
Write all instance data into a file

@return File, containing instance data
@throws IOException
Write all instance data into a file @return File containing instance data @throws IOException
private static File createIPFile() throws IOException {
		File file = File.createTempFile("ipaddress", ".txt");
		file.deleteOnExit();
		Writer writer = new OutputStreamWriter(new FileOutputStream(file));
		DescribeInstancesRequest request = new DescribeInstancesRequest();
		request.setInstanceIds(activeInstances);
		DescribeInstancesResult res = ec2.describeInstances(request);
		List<Reservation> reservations = res.getReservations();
		List<Instance> instances;
		int count = 0;
		for (Reservation r : reservations) {
			instances = r.getInstances();
			for (Instance ins : instances) {
				log.info(ins.getPublicIpAddress() + "," + ins.getPublicDnsName());
				writer.write(count + "," + ins.getInstanceId() + "," + ins.getPublicIpAddress() + ","
						+ ins.getPublicDnsName() + "\n");
				activePublicDnsName.add(ins.getPublicDnsName());
				mapOfInstances.put(count, ins.getPublicIpAddress());
				count++;
			}
		}
		writer.close();
		return file;
	}
private static File createIPFile ( ) throws IOException { File file = File . createTempFile ( "ipaddress" , ".txt" ) ; file . deleteOnExit ( ) ; Writer writer = new OutputStreamWriter ( new FileOutputStream ( file ) ) ; DescribeInstancesRequest request = new DescribeInstancesRequest ( ) ; request . setInstanceIds ( activeInstances ) ; DescribeInstancesResult res = ec2 . describeInstances ( request ) ; List < Reservation > reservations = res . getReservations ( ) ; List < Instance > instances ; int count = 0 ; for ( Reservation r : reservations ) { instances = r . getInstances ( ) ; for ( Instance ins : instances ) { log . info ( ins . getPublicIpAddress ( ) + "," + ins . getPublicDnsName ( ) ) ; writer . write ( count + "," + ins . getInstanceId ( ) + "," + ins . getPublicIpAddress ( ) + "," + ins . getPublicDnsName ( ) + "\n" ) ; activePublicDnsName . add ( ins . getPublicDnsName ( ) ) ; mapOfInstances . put ( count , ins . getPublicIpAddress ( ) ) ; count ++ ; } } writer . close ( ) ; return file ; }
Write all instance data into a file
Write all instance data into a file