Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Cluster properties and rename DeploymentId to ClusterId #34

Merged
merged 12 commits into from
Oct 3, 2016
20 changes: 10 additions & 10 deletions Docs/Deploy&Host_an_App_in_YAMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ namespace WebApp
{
public static string Id;
public static string Version;
public static string DeploymentId;
public static string ClusterId;

static void Main(string[] args)
{
Id = args[0];
Version = args[1];
DeploymentId = args[2];
ClusterId = args[2];

string baseUrl = string.Format("http://{0}/{1}/", GetIpAddress(), Id);
Console.WriteLine("Url is: " + baseUrl);
Expand Down Expand Up @@ -101,9 +101,9 @@ namespace WebApp
{{
'Id': '{0}',
'Version': '{1}',
'Cloud Service Deployment Id': '{2}'
'Yams Cluster Id': '{2}'
}}
", App.Id, App.Version, App.DeploymentId);
", App.Id, App.Version, App.ClusterId);

return JObject.Parse(json);
}
Expand All @@ -121,7 +121,7 @@ Before deploying an application in YAMS, we need to add a YAMS specific configur
```json
{
"ExeName": "WebApp.exe",
"ExeArgs": "${Id} ${Version} ${DeploymentId}"
"ExeArgs": "${Id} ${Version} ${ClusterId}"
}
```

Expand All @@ -144,7 +144,7 @@ To deploy **WebApp** to YAMS, follow the steps below:
{
"Id": "WebApp",
"Version": "1.0.0",
"DeploymentIds": [ "MY_DEPLOYMENT_ID" ]
"TargetClusters": [ "MY_CLUSTER_ID" ]
}
]
}
Expand All @@ -162,7 +162,7 @@ The result should look like the following:
{
"Id": "WebApp",
"Version": "1.0.0",
"Cloud Service Deployment Id": "MY_DEPLOYMENT_ID"
"Yams Cluster Id": "MY_CLUSTER_ID"
}
```

Expand Down Expand Up @@ -234,12 +234,12 @@ To deploy the new version (let's say `2.0.0`) side-by-side with the currently ru
{
"Id": "WebApp",
"Version": "1.1.0",
"DeploymentIds": [ "MY_DEPLOYMENT_ID" ]
"TargetClusters": [ "MY_DEPLOYMENT_ID" ]
},
{
"Id": "WebApp",
"Version": "2.0.0",
"DeploymentIds": [ "MY_DEPLOYMENT_ID" ]
"TargetClusters": [ "MY_DEPLOYMENT_ID" ]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should you update these to MY_CLUSTER_ID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep thanks

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
]
}
Expand All @@ -251,4 +251,4 @@ That's it! The two versions should be now happily running side-by-side.
To remove an app from YAMS, simply remove the corresponding entry from the `DeploymentConfig.json` file. YAMS will terminate the corresponding process and remove the app. You can also delete the associated files from the blob storage if you are never going to use this app again or keep it there to preserve history of deployments and to allow reverts. In fact, to revert a deployment in YAMS, simply edit the `DeploymentConfig.json` file and replace the current version of the app (the version to be reverted) with the old version (the version to revert to).

# Source code
The source code associated with this tutorial can be found in the [Samples/WebApp](../Samples/WebApp) directory.
The source code associated with this tutorial can be found in the [Samples/WebApp](../Samples/WebApp) directory.
22 changes: 11 additions & 11 deletions Docs/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ The `DeploymentConfig.json` file contains information about what application sho
{
"Id": "app1",
"Version": "1.0.0",
"DeploymentIds": [ "YAMS_CLUSTER_ID" ]
"TargetClusters": [ "YAMS_CLUSTER_ID" ]
},
{
"Id": "app2",
"Version": "1.0.1",
"DeploymentIds": [ "YAMS_CLUSTER_ID", "YAMS_CLUSTER_ID_OTHER" ]
"TargetClusters": [ "YAMS_CLUSTER_ID", "YAMS_CLUSTER_ID_OTHER" ]
},
]
}
```

The `DeploymentIds` field identifies the Yams clusters where an application should be deployed. With a single Worker Role, it is the same deployment id of the Azure cloud service where the Yams cluster is deployed. If you have multiple Worker Roles in the same Azure cloud service, then it is a concatenation of the deployment id of the Azure cloud service and the name of the Worker Role.
The `TargetClusters` field identifies the Yams clusters where an application should be deployed.

## Deploying Yams to a cloud service
Yams can be deployed to Azure like any typical cloud service. The [Deploy YAMS tutorial](Deploy_YAMS.md) explains the steps needed to deploy Yams to Azure.

## Scanning blob storage
When a Yams cluster is deployed to a cloud service, each instance in the cluster reads the `DeploymentConfig.json` file and deploy all apps that have the corresponding `DeploymentId` (typically the deployment id of the cloud service where the Yams cluster is deployed). Then, periodically, each Yams instance scans the `DeploymentConfig.json` file for changes and takes the appropriate actions. There are three types of changes that can occur:
When a Yams cluster is deployed to a cloud service, each instance in the cluster reads the `DeploymentConfig.json` file and deploy all apps that have the corresponding `ClusterId` (typically the deployment id of the cloud service where the Yams cluster is deployed). Then, periodically, each Yams instance scans the `DeploymentConfig.json` file for changes and takes the appropriate actions. There are three types of changes that can occur:

1. **An application is added**
2. **An application is removed**
Expand All @@ -84,7 +84,7 @@ Notice the ${Id} symbol in the ExeArgs which will be substituted with the actual
* ${Version.Major}
* ${Version.Minor}
* ${Version.Build}
* ${DeploymentId}: the cloud service deployment id.
* ${ClusterId}: the Yams cluster id.
* ${InstanceId}: the current VM instance id.

Note that Yams also support running multiple versions of the same app side-by-side. Please see the [Deploy and Host an App in YAMS tutorial](Deploy&Host_an_App_in_YAMS.md) to learn more about this feature.
Expand All @@ -106,20 +106,20 @@ One of the main goals of Yams is sharing infrastructure to reduce cost. In fact,

Another use case where sharing infrastructure can result in large savings is in testing environments. In fact, without sharing infrastructure, at least one additional VM is needed for testing each microservice. Considering that testing (such as running integration and end to end tests) doesn't have high performance requirements and that microservices are not all tested at the same time, using a pool of shared VMs for testing can significantly reduce the number of required VMs.

To deploy multiple apps to the same Yams cluster, simply use the same deployment id as shown below:
To deploy multiple apps to the same Yams cluster, simply use the same cluster id as shown below:
```
{
"Applications":
[
{
"Id": "app1",
"Version": "1.0.0",
"DeploymentIds": [ "cluster_1_deploymentid" ]
"TargetClusters": [ "cluster_1_id" ]
},
{
"Id": "app2",
"Version": "1.0.1",
"DeploymentIds": [ "cluster_1_deploymentid" ]
"TargetClusters": [ "cluster_1_id" ]
},
]
}
Expand All @@ -136,17 +136,17 @@ To address this issue, microservices can be deployed to different Yams clusters
{
"Id": "Microservice1",
"Version": "1.0.0",
"DeploymentIds": [ "cluster_1_deploymentid" ]
"TargetClusters": [ "cluster_1_id" ]
},
{
"Id": "Microservice2",
"Version": "1.0.1",
"DeploymentIds": [ "cluster_2_deploymentid" ]
"TargetClusters": [ "cluster_2_id" ]
},
{
"Id": "Microservice3",
"Version": "2.0.0",
"DeploymentIds": [ "cluster_2_deploymentid" ]
"TargetClusters": [ "cluster_2_id" ]
},
]
}
Expand Down
82 changes: 47 additions & 35 deletions Docs/YAMS_Storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@ This tutorial demonstrates the use of the `IDeploymentRepository` Api which can

* Create a proxy to the Yams storage
```csharp
IDeploymentRepository deploymentRepository = new BlobStorageDeploymentRepository("my_data_connection_string");
IDeploymentRepository deploymentRepository = BlobStorageDeploymentRepository.Create("my_data_connection_string");
```

* Fetch the DeploymentConfig
```csharp
DeploymentConfig deploymentConfig = await deploymentRepository.FetchDeploymentConfig();

// DeploymentConfig implements IEnumerable.
foreach(AppDeploymentConfig appDeploymentConfig in deploymentConfig)
{
AppIdentity appIdentity = appDeploymentConfig.AppIdentity;
IEnumerable<string> targetClusters = appDeploymentConfig.TargetClusters;
}
```

* Deploy a new application
```csharp
AppIdentity appIdentity = new AppIdentity("AppId", "1.0.0");

// Upload the application binaries
await deploymentRepository.UploadApplicationBinaries(appIdentity, localBinariesDirPath, ConflictResolutionMode.FailIfBinariesExist);

// Update the DeploymentConfig. Note that the DeploymentConfig class is immutable
DeploymentConfig deploymentConfig = await deploymentRepository.FetchDeploymentConfig();
deploymentConfig = deploymentConfig.AddApplication(appIdentity, "cloudservice_deployment_id");
deploymentConfig = deploymentConfig.AddApplication(appIdentity, "yams_cluster_id");

// The application will only be deployed to the cluster when the DeploymentConfig is published
await deploymentRepository.PublishDeploymentConfig(deploymentConfig);
```
Expand All @@ -27,12 +39,12 @@ This tutorial demonstrates the use of the `IDeploymentRepository` Api which can
```csharp
// Upload the new binaries
await deploymentRepository.UploadApplicationBinaries(newAppIdentity, localBinariesDirPath, ConflictResolutionMode.FailIfBinariesExist);

// Fetch and update the DeploymentConfig
DeploymentConfig deploymentConfig = await deploymentRepository.FetchDeploymentConfig();
deploymentConfig = deploymentConfig.RemoveApplication(oldAppIdentity, "cloudservice_deployment_id");
deploymentConfig = deploymentConfig.AddApplication(newAppIdentity, "cloudservice_deployment_id");
deploymentConfig = deploymentConfig.RemoveApplication(oldAppIdentity, "yams_cluster_id");
deploymentConfig = deploymentConfig.AddApplication(newAppIdentity, "yams_cluster_id");

// The update will be performed when the new DeploymentConfig is published
await deploymentRepository.PublishDeploymentConfig(deploymentConfig);

Expand All @@ -42,44 +54,44 @@ This tutorial demonstrates the use of the `IDeploymentRepository` Api which can

* Remove an application
```csharp
// Update the DeploymentConfig
DeploymentConfig deploymentConfig = await deploymentRepository.FetchDeploymentConfig();

// Remove the app from the DeploymentConfig
deploymentConfig = deploymentConfig.RemoveApplication(appIdentity, "cloudservice_deployment_id");
// Update the DeploymentConfig
DeploymentConfig deploymentConfig = await deploymentRepository.FetchDeploymentConfig();

// The app will be shutdown when the DeploymentConfig is published
await deploymentRepository.PublishDeploymentConfig(deploymentConfig);
// Remove the app from the DeploymentConfig
deploymentConfig = deploymentConfig.RemoveApplication(appIdentity, "yams_cluster_id");

// You can also cleanup the old binaries if you're not planing to revert back to it in the future.
await deploymentRepository.DeleteApplicationBinaries(appIdentity);
// The app will be shutdown when the DeploymentConfig is published
await deploymentRepository.PublishDeploymentConfig(deploymentConfig);

// You can also cleanup the old binaries if you're not planing to revert back to it in the future.
await deploymentRepository.DeleteApplicationBinaries(appIdentity);
```

* Other DeploymentConfig Apis
```csharp
// Get the list of apps Ids
IEnumerable<string> appIds = deploymentConfig.ListApplications();
// Get the list of apps Ids
IEnumerable<string> appIds = deploymentConfig.ListApplications();

// Get the list of applications deployed to a given yams cluster
appIds = deploymentConfig.ListApplications("MyDeploymentId");
// Get the list of applications deployed to a given yams cluster
appIds = deploymentConfig.ListApplications("yams_cluster_id");

// Get the list of versions of a given app
IEnumerable<string> versions = deploymentConfig.ListVersions("MyAppId");
// Get the list of versions of a given app
IEnumerable<string> versions = deploymentConfig.ListVersions("MyAppId");

// Get the list of versions of a given app that are deployed on a given Yams cluster
versions = deploymentConfig.ListVersions("myAppId", "MyDeploymentId");
// Get the list of versions of a given app that are deployed on a given Yams cluster
versions = deploymentConfig.ListVersions("myAppId", "yams_cluster_id");

// List the yams clusters where an app is deployed
IEnumerable<string> deploymentIds = deploymentConfig.ListDeploymentIds("MyAppId");
// List the yams clusters where an app is deployed
IEnumerable<string> clusterIds = deploymentConfig.ListClusters("MyAppId");

// List the yams clusters where a version of an app is deployed
deploymentIds = deploymentConfig.ListDeploymentIds(new AppIdentity("MyAppId", "1.0.0"));
// List the yams clusters where a version of an app is deployed
clusterIds = deploymentConfig.ListClusters(new AppIdentity("MyAppId", "1.0.0"));

// Add a application to the DeploymentConfig.json
deploymentConfig.AddApplication(new AppIdentity("AppId", "2.0.0"), "DeploymentId");
// Add a application to the DeploymentConfig.json
deploymentConfig.AddApplication(new AppIdentity("AppId", "2.0.0"), "yams_cluster_id");

// Remove an application, a specific version or a specific deployment:
deploymentConfig.RemoveApplication("MyAppId");
deploymentConfig.RemoveApplication(new AppIdentity("MyAppId", "1.0.0"));
deploymentConfig.RemoveApplication(new AppIdentity("MyAppId", "1.0.0"), "MyDeploymentId");
// Remove an application, a specific version or a specific cluster:
deploymentConfig.RemoveApplication("MyAppId");
deploymentConfig.RemoveApplication(new AppIdentity("MyAppId", "1.0.0"));
deploymentConfig.RemoveApplication(new AppIdentity("MyAppId", "1.0.0"), "yams_cluster_id");
```
4 changes: 2 additions & 2 deletions Samples/WebApp/WebApp/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ public class App
{
public static string Id;
public static string Version;
public static string DeploymentId;
public static string ClusterId;

static void Main(string[] args)
{
Id = args[0];
Version = args[1];
DeploymentId = args[2];
ClusterId = args[2];

Version version = new Version(Version);
string apiVersion = string.Format("{0}.{1}", version.Major, version.Minor);
Expand Down
2 changes: 1 addition & 1 deletion Samples/WebApp/WebApp/AppConfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ExeName": "WebApp.exe",
"ExeArgs": "${Id} ${Version} ${DeploymentId}"
"ExeArgs": "${Id} ${Version} ${ClusterId}"
}
2 changes: 1 addition & 1 deletion Samples/WebApp/WebApp/ApplicationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public JObject GetInfo()
'Version': '{1}',
'Cloud Service Deployment Id': '{2}'
}}
", App.Id, App.Version, App.DeploymentId);
", App.Id, App.Version, App.ClusterId);

return JObject.Parse(json);
}
Expand Down
6 changes: 5 additions & 1 deletion Samples/YamsStudio/DeploymentRepositoryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
// -------------------------------------------------------------------

using Etg.Yams.Azure.Storage;
using Etg.Yams.Json;
using Etg.Yams.Storage;
using Etg.Yams.Storage.Config;
using Newtonsoft.Json.Serialization;

namespace YamsStudio
{
public class DeploymentRepositoryFactory : IDeploymentRepositoryFactory
{
public IDeploymentRepository CreateRepository(string connectionString)
{
return new BlobStorageDeploymentRepository(connectionString);
return new BlobStorageDeploymentRepository(connectionString, new JsonDeploymentConfigSerializer(
new JsonSerializer(new DiagnosticsTraceWriter())));
}
}
}
Loading