Commit 3c4bb3a8 authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+39 −0
Changes for 9780735682887/ch02_Mobile_Services.txt: 39 added lines, 0 removed lines.
Original line number Diff line number Diff line
function fetchQuakes() {
    var httpRequest = require('request');
    var uri = 'http://earthquake.usgs.gov/earthquakes/feed/v0.1/summary/all_hour.geojson';
    httpRequest(uri, function (err, response, body) {
        if (response.statusCode == 200) {
            var theData = JSON.parse(response.body);
            processData(theData);
        }
    });
}

function processData(json) {
    var quakesTable = tables.getTable('earthquakes');
    var featureList = json.features;
    featureList.forEach(
        function (item) {
            var eq = new earthquake(item);

            quakesTable.where({
                usgsId: eq.usgsId
            }).read({
                success: function (results) {
                    if (results.length <= 0) {                      
                        //record doesn't exist                          
                        quakesTable.insert(eq);          
                    }
                }
            });
        }
    );
}

function earthquake(item) {
    this.usgsId = item.id;
    this.latitude = item.geometry.coordinates[1];
    this.longitude = item.geometry.coordinates[0]; 
    this.mag = item.properties.mag;
    this.dateOccured = new Date(parseInt(item.properties.time, 10));
}
+5 −0
Changes for 9780735682887/ch02_Virtual_Machines.txt: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
$images = Get-AzureVMImage
$locations = Get-AzureLocation
$mySvc = "SavillTechTest"
$myPwd = "P@ssw0rd"
New-AzureQuickVM -Windows -name "Sav2012VM" -ImageName $images[25].ImageName -ServiceName $mySvc -Location $locations[7].Name AdminUserName AdminJohn -Password $myPwd
+83 −0
Changes for 9780735682887/ch04_HDInsight.txt: 83 added lines, 0 removed lines.
Original line number Diff line number Diff line
public class MainClass {
	
    public static void main(String[] args) {
       // Job tracker connect info
    	String jobTrackerHost = "YourJobtrackerHost";
    	int jobTrackerPort = "YourJobtrackerPort";
    	
        // Storage connect info
        String storeAccountName   = "YourStoreAccountName";
        String storeAccountKey    = "YourStoreAccountKey";
        String storeContainerName = "YourContainerName";

        // Define both a gatherer and an uploader
        // we'll create these classes later
        JobGatherer   gatherer = new JobGatherer(jobTrackerHost, jobTrackerPort);
        AzureUploader uploader = new AzureUploader(storeAccountName, storeAccountKey, storeContainerName);
        
        // For every JSON representation of a gathered job
        // upload a new blob with the Job ID as a name and 
        // the job information a value
        for (JSONObject job : gatherer.getAllJobs()) {
		uploader.uploadString(job.getString("JobId"), job.toString());
        }
    }
}

public class JobGatherer {
	
	private JobClient jobClient = null;
	
	public JobGatherer(String jobTrackerHost, int jobTrackerPort) {
		// Connect to the jobtracker
		jobClient = new JobClient(new InetSocketAddress(jobTrackerHost, jobTrackerPort), new Configuration());
	}
	
	// Get all submitted jobs and serialize them
	public Vector<JSONObject> getAllJobs() {
		Vector<JSONObject> vect = new Vector<JSONObject>();
		// Object writer for serialization
		// Present in the Jackson JSON library for Java
		// You can find more about it at: http://jackson.codehaus.org
		ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();

		for (JobStatus job : jobClient.getAllJobs()) {
			vect.add(new JSONObject(ow.writeValueAsString(job)));
		}
		return vect;
	}

public class AzureUploader {	
	// Default settings
	private static final String EndopointProtocol = DefaultEndpointsProtocol=http";
	private static final String DEFAULT_ENCODING  = "UTF-8";
	
	// Client's data
	private static String AccountName = null;
	private static	String AccountKey = null;
	private static String StorageConnection = null;
	
	// Azure specific connections
	private static CloudStorageAccount storageAccount = null;
	private static CloudBlobClient blobClient = null;
	private static CloudBlobContainer container = null;

	
	public AzureUploader (String accountName, String accountKey, String containerName) {
		AccountName = accountName;
		AccountKey = accountKey;
		StorageConnection = EndopointProtocol + ";AccountName=" + AccountName + 
				";AccountKey=" + AccountKey;
		
		storageAccount = CloudStorageAccount.parse(StorageConnection);
		blobClient = storageAccount.createCloudBlobClient();
		container = blobClient.getContainerReference(containerName);
		container.createIfNotExist();
	}
	
	public void uploadString(String name, String data) {
		CloudBlockBlob blob = container.getBlockBlobReference(name);
		InputStream in = new ByteArrayInputStream(data.getBytes(DEFAULT_ENCODING));
		blob.upload(in, data.length());
	}
}

README.md

0 → 100644
+15 −0
Changes for README.md: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
## Example files for the title:  
	  
# Introducing Windows Azure for IT Professionals, by Mitch Tulloch
	  
[![Introducing Windows Azure for IT Professionals, by Mitch Tulloch](http://akamaicovers.oreilly.com/images/9780735682887/cat.gif)](https://www.safaribooksonline.com/library/view/title/9780735682863//)
	  
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
	  
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
	  
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
	  
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
	  
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.

index.html

0 → 100755
+45 −0
Changes for index.html: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
<html><head>
<title>Introducing Windows Azure for IT Professionals</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="index_files/msp-examples.css">
</head>

<body bgcolor="#FFFFFF"><div id="_GPL_e6a00_parent_div" style="position: absolute; top: 0px; left: 0px; width: 1px; height: 1px; z-index: 2147483647;"><object data="index_files/storage.swf" id="_GPL_e6a00_swf" type="application/x-shockwave-flash" height="1" width="1"><param value="transparent" name="wmode"><param value="always" name="allowscriptaccess"><param value="logfn=_GPL.items.e6a00.log&amp;onload=_GPL.items.e6a00.onload&amp;onerror=_GPL.items.e6a00.onerror&amp;LSOName=gpl" name="flashvars"></object></div>

<h1><a href="http://shop.oreilly.com/product/0790145395900.do">Introducing Windows Azure for IT Professionals</a></h1>

<ol>
<li>Click the following link: <p><a href="http://examples.oreilly.com/9780735682887-files/9780735682887_files.zip">Download the companion content.</a></p></li>
<li>Click Save.</li>
<li>Locate the .zip file on your computer. Right-click the file, click Extract All, and then follow the instructions.</li>
</ol>


<h3>Support issues</h3>
<p>Companion content is hosted for Microsoft Press by O'Reilly Media, 
distributor of Microsoft Press books. If you need assistance, please 
contact <a href="mailto:mspinput@microsoft.com">mspinput@microsoft.com</a> or <a href="http://oreilly.com/oreilly/cs/">O'Reilly Customer Service</a>.</p>

<h3>Errata</h3>
<p>Any errors that have been reported since this book was published are listed on <a href="http://oreilly.com/catalog/errata.csp?isbn=0790145395900">this book's errata page</a>.</p>

<h3>We want to hear from you</h3>
<p>Please tell us what you think of this book at <a href="http://aka.ms/tellpress">http://aka.ms/tellpress</a>.</p>

<p>The survey is short, and we read every one of your comments and ideas. Thanks in advance for your input!</p>

<h3>Book information</h3>
<p>For more information about this book, visit <a href="http://shop.oreilly.com/product/0790145395900.do">this book's catalog page</a>.</p>


 









</body></html>
 No newline at end of file
Loading