Example #1
0
        public void CreateVersion(Version version)
        {
            if (version == null)
                throw new ArgumentNullException("version", "Version cannot be null.");
            if (version.AppKey == Guid.Empty)
                throw new ArgumentException("App key cannot be empty.", "version.AppKey");

            try
            {
                using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                {
                    var appsController = new Apps(Context);
                    var app = appsController.GetApp(version.AppKey);
                    version.GroupKey = app.GroupKey;

                    var indexesController = new Internal.Indexes(Context);

                    using (var stream = version.Serialise())
                    {
                        string indexPath = GetAppVersionsIndexPath(version.AppKey);
                        var index = indexesController.LoadIndex(indexPath);
                        if (index.Entries.Any(e => e.Key == version.Key))
                        {
                            throw new DeploymentException("Index already contains entry for given key!");
                        }

                        using (var putResponse = client.PutObject(new PutObjectRequest()
                        {
                            BucketName = Context.BucketName,
                            Key = string.Format("{0}/{1}/{2}", STR_VERSIONS_CONTAINER_PATH, version.Key.ToString("N"), STR_INFO_FILE_NAME),
                            InputStream = stream,
                        })) { }

                        index.Entries.Add(new Internal.EntityIndexEntry() { Key = version.Key, Name = CreateVersionIndexName(version) });
                        Internal.Indexes.NameSortIndex(index, true);
                        indexesController.UpdateIndex(indexPath, index);
                    }
                }
            }
            catch (AmazonS3Exception awsEx)
            {
                throw new DeploymentException("Failed creating version.", awsEx);
            }
            catch (Exception ex)
            {
                throw new DeploymentException("Failed creating version.", ex);
            }
        }
Example #2
0
        public static App Run(ControllerConfiguration context, Guid groupKey)
        {
            var appsController = new Apps(context);

            var searchEmpty = appsController.SearchGroupApps(groupKey);
            Debug.Assert(searchEmpty.TotalCount == 0);
            Debug.Assert(searchEmpty.Apps.Count() == 0);

            var testApp = new App() { Name = "Test App", GroupKey = groupKey, DeploymentDirectory = "TestApp" };
            appsController.CreateApp(testApp);
            var createdApp = appsController.GetApp(testApp.Key);
            Debug.Assert(createdApp.Name == testApp.Name);
            Debug.Assert(createdApp.GroupKey == testApp.GroupKey);

            var searchSingle = appsController.SearchGroupApps(groupKey);
            Debug.Assert(searchSingle.TotalCount == 1);
            Debug.Assert(searchSingle.Apps.Count() == 1);
            Debug.Assert(searchSingle.Apps.First().Key == createdApp.Key);
            Debug.Assert(searchSingle.Apps.First().Name == createdApp.Name);

            createdApp.Tags.Add("Foo", "Bar");
            appsController.UpdateApp(createdApp);

            var taggedApp = appsController.GetApp(testApp.Key);
            Debug.Assert(taggedApp.GroupKey == createdApp.GroupKey);
            Debug.Assert(taggedApp.Tags.ContainsKey("Foo"));
            Debug.Assert(taggedApp.Tags["Foo"] == "Bar");
            var searchUpdated = appsController.SearchGroupApps(groupKey);
            Debug.Assert(searchUpdated.TotalCount == 1);
            Debug.Assert(searchUpdated.Apps.Count() == 1);
            Debug.Assert(searchUpdated.Apps.First().Key == createdApp.Key);
            Debug.Assert(searchUpdated.Apps.First().Name == createdApp.Name);

            taggedApp.Name = "Updated Test App";
            appsController.UpdateApp(taggedApp);

            var renamedApp = appsController.GetApp(testApp.Key);
            Debug.Assert(renamedApp.Name == taggedApp.Name);
            Debug.Assert(renamedApp.GroupKey == taggedApp.GroupKey);
            var searchRenamed = appsController.SearchGroupApps(groupKey);
            Debug.Assert(searchRenamed.TotalCount == 1);
            Debug.Assert(searchRenamed.Apps.Count() == 1);
            Debug.Assert(searchRenamed.Apps.First().Key == taggedApp.Key);
            Debug.Assert(searchRenamed.Apps.First().Name == taggedApp.Name);

            Searching(groupKey, appsController, createdApp);

            var searchDeleted = appsController.SearchGroupApps(groupKey);
            Debug.Assert(searchDeleted.TotalCount == 1);
            Debug.Assert(searchDeleted.Apps.Count() == 1);
            Debug.Assert(searchDeleted.Apps.First().Key == taggedApp.Key);
            Debug.Assert(searchDeleted.Apps.First().Name == taggedApp.Name);

            appsController.UpdateApp(testApp);
            var searchReset = appsController.SearchGroupApps(groupKey);
            Debug.Assert(searchReset.TotalCount == 1);
            Debug.Assert(searchReset.Apps.Count() == 1);
            Debug.Assert(searchReset.Apps.First().Key == testApp.Key);
            Debug.Assert(searchReset.Apps.First().Name == testApp.Name);

            // Create default test apps.
            appsController.CreateApp(new App() { Key = new Guid("8b245840-96be-4c9b-889e-06985fc63498"), GroupKey = new Guid("5615c002-2d9a-46c4-a9a3-26b2b19cd790"), Name = "Plywood Toolkit", DeploymentDirectory = "PlywoodToolkit", MajorVersion = "0.1", Revision = 11 });
            appsController.CreateApp(new App() { Key = new Guid("6eaf852b-5b91-4ce6-9e74-ce57ee2aef9d"), GroupKey = new Guid("5615c002-2d9a-46c4-a9a3-26b2b19cd790"), Name = "Sawmill Test", DeploymentDirectory = "SawmillTest", MajorVersion = "0.1", Revision = 1 });

            return testApp;
        }