diff --git a/challenges/Module0-Getting Started.MD b/challenges/Module0-Getting Started.MD index f4c4ddd..f080aa9 100644 --- a/challenges/Module0-Getting Started.MD +++ b/challenges/Module0-Getting Started.MD @@ -4,7 +4,7 @@ In this lab, you will be deploying pre-requisite infrastructure which is required for CosmosDB Hackfest. #### Prerequisites * Windows or a Mac machine with HTML5 supported browser such as Microsoft Edge, Internet Explorer, Chrome or Firefox. -* You should have registered in the training portal https://azuretraining.spektrasystems.com and received the confirmation message with the credentials to login to the Azure portal. +* You should have registered in the training portal http://experience-azure-mgmt.azurewebsites.net and received the confirmation message with the credentials to login to the Azure portal.
#### Time Estimate diff --git a/challenges/Module2-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD b/challenges/Module2-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD index e3107e3..50c17a0 100644 --- a/challenges/Module2-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD +++ b/challenges/Module2-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD @@ -1,8 +1,8 @@ # Module 2: Migrate MongoDB Applications to Azure Cosmos DB(Mongo API) -## Scenario 1 Understand the Flight Reservation App, Local MongoDB and test Application +## Scenario 1: Understand the Flight Reservation App, Local MongoDB and test Application ### Understand Flight reservation application #### Access Jump VM -1. From azure portal, Go to virtual machine and select the JumpVM. In Overview section, click on Connect button. It will show username with IP address copy that IP address.
+1. From azure portal, go to virtual machine and select the JumpVM. In Overview section, click on **Connect** button. It will show username with IP address copy that IP address.

1. Click on start button and search for **Remote Desktop Connection** and click on it.
1. Remote Desktop Connection window will pop-up in that provide the IP Address that you copied in above step.
@@ -21,15 +21,15 @@ 1. VS Code should have src folder already opened, Notice the folders hierarchy

1. ContosoAir application is 3-tiered application, One frontend application built on AngularJS named **ContosoAir.Website** and API application named **ContosoAir.Services** build with NodeJS and a data backend running on MongoDB.
-1. All connectivity information required for the API application is maintained in **config.js** , As shown below.
+1. All connectivity information required for the API application is maintained in **config.js**, As shown below.

1. Following is the file system location for application binaries /home/CosmosDB-Hackfest/ContosoAir/src/.

#### Access Local MongoDB and Verify Collections -1. Open the **Terminal**, then start the mongodb Service by running **sudo service mongod start** and verify the mongoDB database while running the mongo as shown below.
+1. Open the **Terminal**, then start the mongodb Service by running **sudo service mongod start** and verify the mongoDB database while running the **mongo** as shown below.

-1. You can also verify the records in mongoDB database while running the following commands. Copy the db_name(contosoairdb3) for future use. Note down that there are 5 collections used by the Application.
+1. You can also verify the records in mongoDB database while running the following commands. Copy the db_name(contosoairdb) for future use. Note down that there are 5 collections used by the Application.
```bash show dbs use @@ -41,9 +41,9 @@ show collections 1. To start the ContosoAir app service layer, go to /home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Services in file system, right click and select **Open Terimal Here** as shown below.

-1. **Open** the **Terminal**and run **npm start** command. Application should start, Incase of any errors make sure you're in right directory as instructed in previous step.Minmize the terminal once command is executed, do not exit or CTRL+C.
+1. **Open** the **Terminal** and run **npm start** command. Application should start, Incase of any errors make sure you're in right directory as instructed in previous step. Minimize the terminal once command is executed, do not exit or CTRL+C.

-1. Now, to start the ContosoAir Website layer, go to /home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Website. Open terminal from there and run **ng serve** command in terminal. Minmize the terminal once command is executed, do not exit or CTRL+C.
+1. Now, to start the ContosoAir Website layer, go to /home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Website. Open terminal from there and run **ng serve** command in terminal. Minimize the terminal once command is executed, do not exit or CTRL+C.

> Note This may take upto a minute to start this website. @@ -56,14 +56,14 @@ show collections 1. Enter **Departure date** and **Return date** in **YYYY-MM-DD** format and click **Find Flights** button.

-## Scenario 2 Migrate Application data to Cosmos DB +## Scenario 2: Migrate Application data to Cosmos DB ### Create Cosmos DB with Mongo API -1. Open Azure Portal with your credential and Click on Add button.
+1. Open **Azure Portal** with your credential, open the resource group which is already created and click on **Add** button.

-1. Search for Azure Cosmos DB and Select it.
+1. Search for Azure Cosmos DB and Select it from results.

-1. Click on create button.
+1. Click on **Create** button.

1. Populate the below parameters as shown below.
* **ID**:(any valid name) @@ -77,61 +77,61 @@ show collections
### Migrate Database to Azure Cosmos DB In this exercise, We will use mongoexport to export the data from MongoDB running locally in the jump-VM and then we will use mongoimport to insert this dataset into newly created Cosmos DB.
-1. Open **Terminal** on Jump VM, (Alternatively you can also access Jump VM on SSH by any ssh tool such as Putty), verify that MongoD Service is running. Issue following commands to export the each collection in the mongo db database to a local bkp file.
+1. Open **Terminal** on Jump VM in which you run the **mongo** command, (Alternatively you can also access Jump VM on SSH by any ssh tool such as Putty), for verifying the MongoD Service is running. Issue following commands to export the each collection in the mongo db database to a local bkp file.
```bash -sudo mongoexport --host localhost --db contosoairdb3 --collection BookingsCollection --out BookingsCollection.bkp -sudo mongoexport --host localhost --db contosoairdb3 --collection DealsCollection --out DealsCollection.bkp -sudo mongoexport --host localhost --db contosoairdb3 --collection FlightsCollection --out FlightsCollection.bkp -sudo mongoexport --host localhost --db contosoairdb3 --collection SeatsCollection --out SeatsCollection.bkp -sudo mongoexport --host localhost --db contosoairdb3 --collection feedbackdb --out feedbackdb.bkp +sudo mongoexport --host localhost --db contosoairdb --collection BookingsCollection --out BookingsCollection.bkp +sudo mongoexport --host localhost --db contosoairdb --collection DealsCollection --out DealsCollection.bkp +sudo mongoexport --host localhost --db contosoairdb --collection FlightsCollection --out FlightsCollection.bkp +sudo mongoexport --host localhost --db contosoairdb --collection SeatsCollection --out SeatsCollection.bkp +sudo mongoexport --host localhost --db contosoairdb --collection feedbackdb --out feedbackdb.bkp ```
2. Now, we will import this MongoDB on Azure Cosmos DB (MongoDB) and replace the **HOST, PORT, USERNAME** and **PASSWORD** with the parameters in below command with values you copied in above step.
```bash -mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb3 --collection BookingsCollection --file BookingsCollection.bkp +mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb --collection BookingsCollection --file BookingsCollection.bkp -mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb3 --collection DealsCollection --file DealsCollection.bkp +mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb --collection DealsCollection --file DealsCollection.bkp -mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb3 --collection FlightsCollection --file FlightsCollection.bkp +mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb --collection FlightsCollection --file FlightsCollection.bkp -mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb3 --collection SeatsCollection --file SeatsCollection.bkp +mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb --collection SeatsCollection --file SeatsCollection.bkp -mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb3 --collection feedbackdb --file feedbackdb.bkp +mongoimport --host : -u -p --ssl --sslAllowInvalidCertificates --db contosoairdb --collection feedbackdb --file feedbackdb.bkp ```
-3. Data is now migrated, lets verify this in Azure Portal, Switch to Azure Portal as launched earlier navigate to Resource groups option present in the favourites menu on the left side panel and select the resource group then click on your newly created Azure Cosmos DB Account.
+3. Data is now migrated, lets verify this in Azure Portal, switch to Azure Portal as launched earlier navigate to Resource groups option present in the favourites menu on the left side panel and select the **Resource Group** then click on your newly created **Azure Cosmos DB Account**.
4. Click on **Data Explorer** option. It will display the collection created in Azure Cosmos DB Account. You should see newly created DB along with collection, you may browse the documents in collections.

### Update Application to use Cosmos DB -1. Go back to Visual Studio Code IDE in JumpVM and navigate to the config.js file under ContosoAir.Services and paste the **URI** value against **DOCUMENT_DB_ENDPOINT**, **PRIMARY KEY** against **DOCUMENT_DB_PRIMARYKEY**, **DOCUMENT_DB_DATABASE** as **contosoairdb3** and **Primary Connection String** Against **MONGO_DB_CONNECTION_STRING** -it should look something like below +1. Go back to Visual Studio Code IDE in JumpVM and navigate to the config.js file under ContosoAir.Services and paste the **HOST** value against **DOCUMENT_DB_ENDPOINT**, **PRIMARY KEY** against **DOCUMENT_DB_PRIMARYKEY**, **DOCUMENT_DB_DATABASE** as **contosoairdb** and **Primary Connection String** Against **MONGO_DB_CONNECTION_STRING** and add database name (contosoairdb) before question mark in connection string. +it should look something like below: ```bash -mongodb://cosmosdb12345:vMTETikja355VZjnJQGC3gwdLaR8xjNlpUq65loZVd4pLvmlG9PB25eqOb7V0EWFnvkqzd9GMp4vjiiDYGLahw==@cosmosdb12345.documents.azure.com:10255/?ssl=true&replicaSet=globaldb +mongodb://cosmosdb12345:vMTETikja355VZjnJQGC3gwdLaR8xjNlpUq65loZVd4pLvmlG9PB25eqOb7V0EWFnvkqzd9GMp4vjiiDYGLahw==@cosmosdb12345.documents.azure.com:10255/*contosoairdb*?ssl=true&replicaSet=globaldb ``` -2. Navigate back to the **Azure Portal** Resource groups option present in the favourites menu on the left side panel and select the resource group "" and click on **Azure Cosmos DB Account** then, click on **Replicate data globally** option present under **SETTINGS** section in Cosmos DB Account blade.
+2. Navigate back to the **Azure Portal** Resource groups option present in the favourites menu on the left side panel and select the **Resource Group** and click on **Azure Cosmos DB Account** then, click on **Replicate data globally** option present under **SETTINGS** section in Cosmos DB Account blade.
3. Copy the **WRITE REGION** and paste it against **DOCUMENT_DB_PREFERRED_REGION** key in **config.js** file which is already opened in Visual Studio Code IDE and save this file.

-4. Open the terminal window running already running with **npm start** for Services application, Exit the application by pressing CTRL+C and start the application again by running **npm start**.
+4. Open the terminal window already running with **npm start** for Services application, Exit the application by pressing CTRL+C and start the application again by running **npm start**.


-5. ContosoAir Website should be running already in other terminal window, You can leave it running as is(No need to stop and restart). -if not running, you can manually start it to by going to /home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Website. Open terminal from there and run **np serve** command in terminal.
+5. ContosoAir Website should be running already in other terminal window, You can leave it running(No need to stop and restart). +if not running, you can manually start it to by going to **/home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Website**. Open terminal from there and run **ng serve** command in terminal.

6. Copy the **localhost URL** [http://localhost:4200](http://localhost:4200) from the **here** and paste it in **Mozilla firefox** browser and press enter.
-7. You will see the sign-up page. Enter your microsoft Credential here.
+7. You will see the sign-up page if you already sign-up it will redirect to **ContosoAir app**. Enter your microsoft Credential here.

8. Once you get login, you will be redirected to **ContosoAir app**.

@@ -160,35 +160,35 @@ You should notice that latency is now changed when loading the flight data >_Physical partitioning_ **Partitioning** _is completely managed by_ **Azure**_. It automatically creates a_ **Logical Partition** _based on the_ **Partition key**. But in this case, just to show you the power of **Partitioning** feature of Azure Cosmos DB, we have created the **Physical partition.** -Configure FlightsCollection data to leverage the Partitions +**Configure FlightsCollection data to leverage the Partitions** -1. In this exercise, We'll create another collection named **FlightsCollectionPartitioned** in existing **contoairdb3** with number of **Stops** as the partition key -1. Open Azure Portal and access the Cosmos DB account created earlier, Go to **Browse** in settings blade +1. In this exercise, we'll create another collection named **FlightsCollectionPartitioned** in existing **contosoairdb** with number of **Stops** as the partition key. +1. Open Azure Portal and access the Cosmos DB account created earlier, Go to **Browse** in settings blade. ![](images/createcollection.jpg) -1. Click on Add Collection Button, Scroll horizontally to see the full dialogue box. Enter **contosoairdb3** as the database ID and **FlightsCollectionPartitioned** as the collection name. Enter **stop** as partition key, leave all other settings as default. +1. Click on **Add Collection** Button, Scroll horizontally to see the full dialogue box. Enter **contosoairdb** as the **Database Id** and **FlightsCollectionPartitioned** as **collection Id**. Enter **stop** as **Shared key**, leave all other settings as default. ![](images/createnewcollection.jpg) -4. In order to use this collection in the application, We need to edit **config.js** of Services application and replace following value with newly created collection. Save the file once changed.
+4. In order to use this collection in the application, we need to edit **config.js** of Services application and replace following value with newly created collection. Save the file once changed.
**DOCUMENT_DB_FLIGHT** 'FlightsCollection', replace with newly created collection with partitioning **DOCUMENT_DB_FLIGHT**: 'FlightsCollectionPartitioned', ![](images/configpartition.jpg) -5. Now We'll insert the the **FlightsCollection** data into this partitioned collection. For this, We've already created a nodejs program named **cosmos_mongo_partition_insert.js** . Run **node cosmos_mongo_partition_insert.js** the ContosoAir.Services root directory. Go to ContosoAir.Services by issuing **cd /home/dbadmin/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Services** You can use **ls** to verify the files in the directory +5. Now we'll insert the the **FlightsCollection** data into this partitioned collection. For this, we already created a nodejs program named **cosmos_mongo_partition_insert.js** . You can use **ls** to verify the files in the directory. In ContosoAir.Services root directory open the **Terminal** and run the **node cosmos_mongo_partition_insert.js** command. ![](images/insertpartitiondat.jpg) 6. Data is now inserted, let's go to Azure portal to verify, Go to **Browse** in settings blade of Cosmos DB Account. -7. You'll see that under documents, there's another column named **stop** along with **id**. Click on Scale and settings to verify the partition. +7. You'll see that under documents, there's another column named **stop** along with **id**. Click on **Scale and settings** to verify the partition. ![](images/scalesettings.jpg) -8. In order to test the application, exit the terminal running **npm start** for the application and start it again +8. In order to test the application, exit the terminal running **npm start** for the application and start it again. > Awesome! In this scenario, you learned the Partitioning feature of Azure Cosmos DB. @@ -199,11 +199,11 @@ replace with newly created collection with partitioning > Replication ensures that your storage account meets the [Service-Level Agreement (SLA) for Storage](https://azure.microsoft.com/support/legal/sla/storage) even in the face of failures. See the SLA for information about Azure Storage guarantees for durability and availability. - > _To test the above scenario of_ **Part D**, _lets replicate the database into multiple regions. Below is the procedure for the same._ + > _To test the above scenario, _lets replicate the database into multiple regions. Below is the procedure for the same._ ### Replicate data globally 1. **Launch** a browser and **navigate** to https://portal.azure.com. **Login** with your Microsoft Azure credentials.
-2. Select the **Azure Cosmos DB account(i.e,cosmosdb321)**.
+2. Select the **Azure Cosmos DB account(MongoDB)**.
3. In the Cosmos DB account page click on **Replicate data globally** tab under the **Settings** tile.

4. In the new page that appear, click on **Add new region** under **Read regions**.
@@ -215,25 +215,25 @@ replace with newly created collection with partitioning > - You can distribute your data to any number of Azure regions, with the click of a button. This enables you to put your data where your users are, ensuring the lowest possible latency to your customers. -5. If you want to add more regions, click on Add new region again and select the required region and click on **Save**. +5. If you want to add more regions, click on **Add new region** again and select the required region and click on **Save**.
> **Note** : > - It takes some time near about 8 to 10 mins to complete the deployment of the resources ### NodeJS Libraries for Geo Replication -CosmosDB with MongoAPI supports same read prefrences available in NodeJS Mongo libraries. With read preferences you can control from where your Reads are happing in a Replicaset and from Mongo DB also in a shard. Let’s go through the different types of read Preferences that are available and what they mean. +CosmosDB with MongoAPI supports same read preference available in NodeJS Mongo libraries. With read preference you can control from where your Reads are happing in a Replicated and from Mongo DB also in a shared. Let’s go through the different types of read Preferences that are available and what they mean. * **ReadPreference.PRIMARY**: Read from primary only. All operations produce an error (throw an exception where applicable) if primary is unavailable. Cannot be combined with tags (This is the default.) * **ReadPreference.PRIMARY_PREFERRED**: Read from primary if available, otherwise a secondary. * **ReadPreference.SECONDARY**: Read from secondary if available, otherwise error. * **ReadPreference.SECONDARY_PREFERRED**: Read from a secondary if available, otherwise read from the primary. -* **ReadPreference.NEAREST**: All modes read from among the nearest candidates, but unlike other modes, NEAREST will include both the primary and all secondaries in the random selection. The name NEAREST is chosen to emphasize its use, when latency is most important. For I/O-bound users who want to distribute reads across all members evenly regardless of ping time, set secondaryAcceptableLatencyMS very high. See “Ping Times” below. A strategy must be enabled on the ReplSet instance to use NEAREST as it requires intermittent setTimeout events, see Db class documentation +* **ReadPreference.NEAREST**: All modes read from among the nearest candidates, but unlike other modes, NEAREST will include both the primary and all secondaries in the random selection. The name NEAREST is chosen to emphasize its use, when latency is most important. For I/O-bound users who want to distribute reads across all members evenly regardless of ping time, set secondaryAcceptableLatencyMS very high. See “Ping Times” below. A strategy must be enabled on the ReplSet instance to use NEAREST as it requires intermittent setTimeout events, see Db class documentation. -Additionally you can now use tags with all the read preferences to actively choose specific sets of regions in a globally distributed Cosmos DB. For example, if you wanto use West US as read region, you can specify this tag { region: ‘West US’, size: ‘large’ } with read prefrences. +Additionally you can now use tags with all the read preferences to actively choose specific sets of regions in a globally distributed Cosmos DB. For example, if you wanto use West US as read region, you can specify this tag { region: ‘West US’, size: ‘large’ } with read preferences. ### Connect Application to Secondary region -Now let's update the application to use secondary region as read region and experience the latency diffrene used earlier. +Now let's update the application to use secondary region as read region and experience the latency differene used earlier. 1. Access JumpVM and launch **Visual Studio Code** if not running already 1. Update your newly added secondary region in Cosmos DB againt **DOCUMENT_DB_PREFERRED_REGION** in **config.js** in Services project. @@ -241,112 +241,27 @@ Now let's update the application to use secondary region as read region and expe 1. Open **flights.controller.js** file available under **api** >> **flights** folder in the Sevices Project.
-1. Scroll down and comment the line number 66 by adding **//** in front of line . This will disable defaulr mode of quering flights data from primary region +1. Scroll down and comment the line number 66 by adding **//** in front of line . This will disable default mode of quering flights data from primary region.
-1. Uncomment line #68 . If you look closely this line is specifying the readprefrence to query data against. +1. Uncomment line #68 . If you look closely this line is specifying the readpreference to query data against.
1. Save both **config.js** and **flights.controller.js** files. -1. Open the terminal window running already running with **npm start** for Services application, Exit the application by pressing CTRL+C and start the application again by running **npm start**.
+1. Open the **Terminal** window already running with **npm start** for Services application, Exit the application by pressing CTRL+C and start the application again by running **npm start**.


-1. ContosoAir Website should be running already in other terminal window, You can leave it running as is(No need to stop and restart). -if not running, you can manually start it to by going to /home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Website. Open terminal from there and run **np serve** command in terminal.
+1. ContosoAir Website should be running already in other terminal window, you can leave it running as is(No need to stop and restart). +if not running, you can manually start it to by going to **/home/CosmosDB-Hackfest/ContosoAir/src/ContosoAir.Website**. Open terminal from there and run **ng serve** command in terminal.

-1. Copy the **localhost URL** [http://localhost:4200](http://localhost:4200) from the **terminal** and paste it in **Mozilla firefox** browser and press enter.
-1. if you see login page, Login with your Microsoft account(live-id) or move to next step.
+1. Copy the **localhost URL** [http://localhost:4200](http://localhost:4200) from **here** and paste it in **Mozilla firefox** browser and press enter.
+1. If you see login page, Login with your Microsoft account(live-id) or move to next step.
1. Enter **Departure date** and **Return date** in **YYYY-MM-DD** format and click **Find Flights** button.
-
+
-You should notice that latency is now changed when loading the flight data in comparision to default +You should notice that latency is now changed when loading the flight data in comparision to default. > _Awesome, you have enable geo-replication on your databases and configured your application to use secondary regions for read operations. - -## Scenario 5: Integration with Azure Functions - -### Create an Azure Function App -In this we will create Azure Function App.
-1. **Login** to **Azure portal** with your credentials and Click on **+New**.
-2. Search for **Function App**.
-
-3. **Click** on **Create**.
-
-4. Provide the parameters to create Function App as defined below.
-* **App Name**: Your unique name to identify the application -* **Subscription**: Leave default -* **Resource Group**: Choose Use Existing and select your available resource group -* **OS**: Windows -* **Hosting Plan**: Consumption Plan -* **Location**: Location of your RG -* **Storage**: Use Existing and choose available storage account
- Click on **Create**.
-
-5. Click on **Go to Resource** Once provisioning is completed.
-
- -### Create a function with Deal Data - - > _Let's create an Azure Function to retrieve data of flight deals._ - -1. Go to **Resource groups** option present in the favourites menu on the left side panel and select the resource group **** and click on Azure Function named ****.
-2. However over the **Functions** under **Functions Apps** and click on **+ sign** besides **Functions**.
-3. Now, click on the **Custom function** link present at the bottom of the page.
-
-4. Click on **C#** template available in **HTTP trigger** section and name the function as "**FetchDealsData**" in **Name** textbox and click **Create** button.
-
-
-5. A function with sample default code would get created. Now, replace the sample default code with the code snippet given below.
- - ```c# - using System.Net; - using System.Linq; - - public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, IEnumerable SelectDealsData) - { - return req.CreateResponse(HttpStatusCode.OK, SelectDealsData); - } - ``` - - > **NOTE:** - > In above code snippet, **IEnumerable<dynamic> SelectDealsData** is a parameter used to fetch the list of **DealsData** collection from Cosmos DB. This method returns the result fetched from Cosmos DB along with **HttpStatusCode** with the help of **CreateResponse** method.
-6. Click on **Save** button.
-7. Now, click on the **Integrate** option listed in **"FetchDealsData"** function in the **Function Apps** blade.
-8. Under **Inputs** section, click on **+ New Input** and select **Azure Cosmos DB** then click **Select** button at the bottom of page.
-
-8. Enter **Document parameter name** as **SelectDealsData**, **Database name** as **contosoairdb** and **Collection name** as **DealsCollection** in respective textboxes.
-9. Copy the **SQL query** given below and paste it into **SQL Query (optional)** textbox.
- - ```sql - select c.id, c.fromName, c.fromCode, c.toName, c.toCode, c.price, c.departTime, c.arrivalTime, c.hours, c.stops, c.since from c - ``` - - > **NOTE:** Above **SQL query** is responsible to get deals details from **DealsCollection** available in Cosmos DB like id, from name, from code, to name, to code, price, depart time, arrival time, hours, stops, since. (Ignore non-mandatory fields) - - ![](image/SqlQuery.jpg) - -10. To enter **Cosmos DB account connection,** click on the **new** link given beside **Cosmos DB account connection** textbox.
-11. You will be redirected to **Cosmos DB Account blade**, select the **MongoDB DB Account** as shown below.
-
-12. Now, click **Save** button ![](img/save.jpg) button.
-13. To check whether the function is integrated, click on **FetchDealsData** function present under **AureFunctionForDeals** function app blade and click on **Test** option present at the right most corner.
-
-14. Select **HTTP method** as **GET** from the dropdown. Then click **Run** button at the bottom. -
-15. Status **200 Ok** will be displayed once the test is completed which signifies that the function is integrated successfully.
-
- - > _Here you go! You have successfully created Azure Function to_ _retrieve flight deals_ _data from_ **Cosmos DB**_._ - -16. In the **Functions Apps** blade, click on **FetchDealsData**.
-17. You will get navigated to function and will find ** Get function URL** link in the top right corner of the page. Click on the link
-18. On clicking ** Get function URL** you will get a popup window with a URL.
-
-19. Click on **Copy** ![](img/Copy.jpg) icon to copy the given URL and paste it against **AZURE\_FUNCTION\_DEALS\_URL:** variable in **config.js file** opened in **Visual Studio 2017** IDE and save the file. - - > _Awesome, you have created Azure Function for Deals data and integrated with Cosmos DB._ - - -## Scenario 6: Azure Cosmos DB Operations: Monitoring, Security and Backup & Restore +## Scenario 5: Azure Cosmos DB Operations: Monitoring, Security and Backup & Restore ## Understanding Cosmos DB Monitoring and SLA's @@ -456,10 +371,10 @@ As a part of Lab, You may want to restrict access to your Database from the Linu Azure Cosmos DB allows you to scale the throughput of a collection by just a couple of clicks.In order to scale up and down the throughput of a Cosmos DB collection, navigate to the Azure Cosmos DB account page and click on Scale. Here you should see the current throughput and options to increase/decrease the throughput. You can make the necessary changes and Click **Save**. - - ![](images/scalethroughput.png) - - + + + + ## Understanding Cosmos DB Backup and restore functionality. Azure Cosmos DB automatically takes backups of all your data at regular intervals. The automatic backups are taken without affecting the performance or availability of your database operations. All your backups are stored separately in another storage service, and those backups are globally replicated for resiliency against regional disasters. The automatic backups are intended for scenarios when you accidentally delete your Cosmos DB container and later require data recovery or a disaster recovery solution. @@ -479,4 +394,3 @@ Azure Cosmos DB retains the last two backups of every partition in the database See this for more inforamtion on Cosmos DB Backup and recovery: https://docs.microsoft.com/en-us/azure/cosmos-db/online-backup-and-restore - diff --git a/challenges/Module3-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD b/challenges/Module3-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD index 8395fcb..85935a3 100644 --- a/challenges/Module3-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD +++ b/challenges/Module3-Migrating MongoDB Apps to Azure Cosmos DB(Mongo API).MD @@ -1,13 +1,13 @@ # Module 3: Migrate MongoDB Application to Azure Cosmos DB(SQL API) ## Access Cosmos DB account with SQL API (created in Module-1) 1. **Launch** a **browser** and navigate to https://portal.azure.com. **Login** with your **Microsoft Azure** credentials.
-2. **Click** on **Resource Group** provided which contains the all the resources, click on created **Azure Cosmos DB account**(with SQL API) under **Overview** tab.
+2. **Click** on **Resource Group** provided which contains all the resources, click on created **Azure Cosmos DB account**(with SQL API) under **Overview** tab.

3. **Click** on **Keys** option present under Cosmos DB Account blade, and copy **URI** and **PRIMARY KEY**.

-4. **Go** back to **Visual Studio Code** IDE and paste the **URI** value against **DOCUMENT_DB_ENDPOINT**, **PRIMARY KEY** against **DOCUMENT_DB_PRIMARYKEY**, **DOCUMENT_DB_DATABASE** and change the **API_MODE** to **SQL** in the **config.js**.
+4. **Go** back to **Visual Studio Code** IDE and paste the **URI** value against **DOCUMENT_DB_ENDPOINT**, **PRIMARY KEY** against **DOCUMENT_DB_PRIMARYKEY**, **DOCUMENT_DB_DATABASE** as **contosoairdb3** and change the **API_MODE** to **SQL** in the **config.js**.
-5. **Navigate** back to the Azure Portal's Resource groups option present in the favourites menu on the left side panel and select the **resource group** and click on **Azure Cosmos DB Account** then, click on **Replicate data globally** option present under **SETTINGS** section in **Cosmos DB Account** blade.
+5. **Navigate** back to the Azure Portal's Resource groups option present in the favourites menu on the left side panel and select the created **resource group** and click on **Azure Cosmos DB Account** then, click on **Replicate data globally** option present under **SETTINGS** section in **Cosmos DB Account** blade.
6. Copy the **WRITE REGION** and paste it against **DOCUMENT_DB_PREFERRED_REGION** in **config.js** file which is already opened in **Visual Studio Code** IDE and save this file.

@@ -37,10 +37,72 @@ ng serve
## Launch the Application -1. Copy the **localhost URL** [http://localhost:4200](http://localhost:4200) from the **terminal** and paste it in **Web Browser** and press enter. There's a shortcut created for your already on desktop for this, you can open website using that as well.
+1. Copy the **localhost URL** [http://localhost:4200](http://localhost:4200) from the **here** and paste it in **Web Browser** and press enter. There's a shortcut created for your already on desktop for this, you can open website using that as well.
1. You will see the **sign-up** page. You need to **login** to App using your **Microsoft Account**(formerly live-id). If you do not have a live-id, you can create one by following instructions given on page.

1. Once you get login, you will be redirected to **ContosoAir app**.

1. Enter **Departure date** and **Return date** in **YYYY-MM-DD** format and click **Find Flights** button.

+ +### Create a function with Deal Data + + > _Let's create an Azure Function to retrieve data of flight deals._ + +1. Go to **Resource groups** option present in the favourites menu on the left side panel and select the resource group **** and click on Azure Function named ****.
+2. However over the **Functions** under **Functions Apps** and click on **+ sign** besides **Functions**.
+3. Now, click on the **Custom function** link present at the bottom of the page.
+
+4. Click on **C#** template available in **HTTP trigger** section and name the function as "**FetchDealsData**" in **Name** textbox and click **Create** button.
+
+
+5. A function with sample default code would get created. Now, replace the sample default code with the code snippet given below.
+ + ```c# + using System.Net; + using System.Linq; + + public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, IEnumerable SelectDealsData) + { + return req.CreateResponse(HttpStatusCode.OK, SelectDealsData); + } + ``` + + > **NOTE:** + > In above code snippet, **IEnumerable<dynamic> SelectDealsData** is a parameter used to fetch the list of **DealsData** collection from Cosmos DB. This method returns the result fetched from Cosmos DB along with **HttpStatusCode** with the help of **CreateResponse** method.
+6. Click on **Save** button.
+7. Now, click on the **Integrate** option listed in **"FetchDealsData"** function in the **Function Apps** blade.
+8. Under **Inputs** section, click on **+ New Input** and select **Azure Cosmos DB** then click **Select** button at the bottom of page.
+
+8. Enter **Document parameter name** as **SelectDealsData**, **Database name** as **contosoairdb** and **Collection name** as **DealsCollection** in respective textboxes.
+9. Copy the **SQL query** given below and paste it into **SQL Query (optional)** textbox.
+ + ```sql + select c.id, c.fromName, c.fromCode, c.toName, c.toCode, c.price, c.departTime, c.arrivalTime, c.hours, c.stops, c.since from c + ``` + + > **NOTE:** Above **SQL query** is responsible to get deals details from **DealsCollection** available in Cosmos DB like id, from name, from code, to name, to code, price, depart time, arrival time, hours, stops, since. (Ignore non-mandatory fields) + + ![](image/SqlQuery.jpg) + +10. To enter **Cosmos DB account connection,** click on the **new** link given beside **Cosmos DB account connection** textbox.
+11. You will be redirected to **Cosmos DB Account blade**, select the **MongoDB DB Account** as shown below.
+
+12. Now, click **Save** button ![](img/save.jpg) button.
+13. To check whether the function is integrated, click on **FetchDealsData** function present under **AureFunctionForDeals** function app blade and click on **Test** option present at the right most corner.
+
+14. Select **HTTP method** as **GET** from the dropdown. Then click **Run** button at the bottom. +
+15. Status **200 Ok** will be displayed once the test is completed which signifies that the function is integrated successfully.
+
+ + > _Here you go! You have successfully created Azure Function to_ _retrieve flight deals_ _data from_ **Cosmos DB**_._ + +16. In the **Functions Apps** blade, click on **FetchDealsData**.
+17. You will get navigated to function and will find ** Get function URL** link in the top right corner of the page. Click on the link
+18. On clicking ** Get function URL** you will get a popup window with a URL.
+
+19. Click on **Copy** ![](img/Copy.jpg) icon to copy the given URL and paste it against **AZURE\_FUNCTION\_DEALS\_URL:** variable in **config.js file** opened in **Visual Studio 2017** IDE and save the file. + + > _Awesome, you have created Azure Function for Deals data and integrated with Cosmos DB._ + diff --git a/challenges/images/Integrate.jpg b/challenges/images/Integrate.jpg index 8628aac..0afa60c 100644 Binary files a/challenges/images/Integrate.jpg and b/challenges/images/Integrate.jpg differ diff --git a/challenges/images/cosmoskeyandurl.jpg b/challenges/images/cosmoskeyandurl.jpg index 39b99f9..8c411db 100644 Binary files a/challenges/images/cosmoskeyandurl.jpg and b/challenges/images/cosmoskeyandurl.jpg differ diff --git a/challenges/images/fnxinfo.jpg b/challenges/images/fnxinfo.jpg index b4493bd..d46cc03 100644 Binary files a/challenges/images/fnxinfo.jpg and b/challenges/images/fnxinfo.jpg differ diff --git a/challenges/images/inputs.jpg b/challenges/images/inputs.jpg new file mode 100644 index 0000000..155bf31 Binary files /dev/null and b/challenges/images/inputs.jpg differ diff --git a/challenges/images/japanreplication.png b/challenges/images/japanreplication.png new file mode 100644 index 0000000..c4286ec Binary files /dev/null and b/challenges/images/japanreplication.png differ diff --git a/challenges/images/jumpvm1.jpg b/challenges/images/jumpvm1.jpg index fae45cc..83b0fd8 100644 Binary files a/challenges/images/jumpvm1.jpg and b/challenges/images/jumpvm1.jpg differ diff --git a/template/azuredeploy.json b/template/azuredeploy.json index 9cb1109..f433180 100644 --- a/template/azuredeploy.json +++ b/template/azuredeploy.json @@ -273,7 +273,7 @@ }, "properties": { "hardwareProfile": { - "vmSize": "Standard_A2_v2" + "vmSize": "Standard_DS2_v2" }, "osProfile": { "computerName": "[parameters('powerBIVirtualMachineName')]",