예제 #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);
            }
        }
예제 #2
0
        public void CreateInstance(Instance instance)
        {
            if (instance == null)
                throw new ArgumentNullException("instance", "Instance cannot be null.");
            if (instance.TargetKey == Guid.Empty)
                throw new ArgumentException("Target key cannot be empty.", "instance.TargetKey");

            using (var stream = instance.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var targetsController = new Targets(Context);
                        if (!targetsController.TargetExists(instance.TargetKey))
                            throw new TargetNotFoundException(String.Format("Target with the key \"{0}\" could not be found.", instance.TargetKey));

                        var indexesController = new Internal.Indexes(Context);

                        string indexPath = GetTargetInstancesIndexPath(instance.TargetKey);
                        var instanceIndex = indexesController.LoadIndex(indexPath);
                        if (instanceIndex.Entries.Any(e => e.Key == instance.Key))
                        {
                            throw new DeploymentException("Target instances index already contains entry for new instance key!");
                        }

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

                        instanceIndex.Entries.Add(new Internal.EntityIndexEntry() { Key = instance.Key, Name = instance.Name });
                        Internal.Indexes.NameSortIndex(instanceIndex);
                        indexesController.UpdateIndex(indexPath, instanceIndex);
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed creating instance.", awsEx);
                }
            }
        }
예제 #3
0
        public void CreateTarget(Target target)
        {
            if (target == null)
                throw new ArgumentNullException("target", "Target cannot be null.");
            if (target.GroupKey == Guid.Empty)
                throw new ArgumentException("Group key cannot be empty.", "target.GroupKey");

            using (var stream = target.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var groupsController = new Groups(Context);
                        if (!groupsController.GroupExists(target.GroupKey))
                            throw new GroupNotFoundException(String.Format("Group with the key \"{0}\" could not be found.", target.GroupKey));

                        var indexesController = new Internal.Indexes(Context);

                        string indexPath = GetGroupTargetsIndexPath(target.GroupKey);
                        var appIndex = indexesController.LoadIndex(indexPath);
                        if (appIndex.Entries.Any(e => e.Key == target.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_TARGETS_CONTAINER_PATH, target.Key.ToString("N"), STR_INFO_FILE_NAME),
                            InputStream = stream,
                        })) { }

                        appIndex.Entries.Add(new Internal.EntityIndexEntry() { Key = target.Key, Name = target.Name });
                        Internal.Indexes.NameSortIndex(appIndex);
                        indexesController.UpdateIndex(indexPath, appIndex);
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed creating target.", awsEx);
                }
            }
        }
예제 #4
0
        public void CreateGroup(Group group)
        {
            if (group == null)
                throw new ArgumentNullException("group", "Group cannot be null.");

            using (var stream = group.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var indexesController = new Internal.Indexes(Context);
                        var index = indexesController.LoadIndex(STR_GROUP_INDEX_PATH);
                        if (index.Entries.Any(e => e.Key == group.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_GROUPS_CONTAINER_PATH, group.Key.ToString("N"), STR_INFO_FILE_NAME),
                            InputStream = stream,
                        })) { }

                        index.Entries.Add(new Internal.EntityIndexEntry() { Key = group.Key, Name = group.Name });
                        Internal.Indexes.NameSortIndex(index);
                        indexesController.UpdateIndex(STR_GROUP_INDEX_PATH, index);
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed creating group.", awsEx);
                }
            }
        }
예제 #5
0
        public void DeleteInstance(Guid instanceKey)
        {
            var instance = GetInstance(instanceKey);
            try
            {
                Plywood.Internal.AwsHelpers.SoftDeleteFolders(Context, string.Format("{0}/{1}", STR_INSTANCES_CONTAINER_PATH, instanceKey.ToString("N")));

                var indexesController = new Internal.Indexes(Context);

                string indexPath = GetTargetInstancesIndexPath(instance.TargetKey);
                var appIndex = indexesController.LoadIndex(indexPath);
                if (appIndex.Entries.Any(e => e.Key == instanceKey))
                {
                    appIndex.Entries.Remove(appIndex.Entries.Single(e => e.Key == instanceKey));
                    Internal.Indexes.NameSortIndex(appIndex);
                    indexesController.UpdateIndex(indexPath, appIndex);
                }
            }
            catch (AmazonS3Exception awsEx)
            {
                throw new DeploymentException("Failed deleting instance.", awsEx);
            }
        }
예제 #6
0
        public void DeleteApp(Guid key)
        {
            var app = GetApp(key);
            try
            {
                Plywood.Internal.AwsHelpers.SoftDeleteFolders(Context, string.Format("{0}/{1}", STR_APPS_CONTAINER_PATH, key.ToString("N")));

                var indexesController = new Internal.Indexes(Context);

                string indexPath = GetGroupAppsIndexPath(app.GroupKey);
                var appIndex = indexesController.LoadIndex(indexPath);
                if (appIndex.Entries.Any(e => e.Key == key))
                {
                    appIndex.Entries.Remove(appIndex.Entries.Single(e => e.Key == key));
                    Internal.Indexes.NameSortIndex(appIndex);
                    indexesController.UpdateIndex(indexPath, appIndex);
                }
            }
            catch (AmazonS3Exception awsEx)
            {
                throw new DeploymentException("Failed deleting app.", awsEx);
            }
        }
예제 #7
0
        public void DeleteVersion(Guid key)
        {
            var version = GetVersion(key);
            try
            {
                Plywood.Internal.AwsHelpers.SoftDeleteFolders(Context, string.Format("{0}/{1}", STR_VERSIONS_CONTAINER_PATH, key.ToString("N")));

                var indexesController = new Internal.Indexes(Context);

                string indexPath = GetAppVersionsIndexPath(version.AppKey);
                var appIndex = indexesController.LoadIndex(indexPath);
                if (appIndex.Entries.Any(e => e.Key == key))
                {
                    appIndex.Entries.Remove(appIndex.Entries.Single(e => e.Key == key));
                    Internal.Indexes.NameSortIndex(appIndex, true);
                    indexesController.UpdateIndex(indexPath, appIndex);
                }
            }
            catch (AmazonS3Exception awsEx)
            {
                throw new DeploymentException(string.Format("Failed deleting version with key \"{0}\"", key), awsEx);
            }
            catch (Exception ex)
            {
                throw new DeploymentException(string.Format("Failed deleting version with key \"{0}\"", key), ex);
            }
        }