Exemple #1
0
 public void AddApp(Guid targetKey, Guid appKey)
 {
     try
     {
         var indexes = new Indexes(Context);
         // We don't need the name so just set to a dash.
         indexes.PutIndexEntry(GetTargetAppsIndexPath(targetKey), new EntityIndexEntry() { Key = appKey, Name = "-" });
     }
     catch (Exception ex)
     {
         throw new DeploymentException(string.Format("Failed adding app with key \"{0}\" to target \"{1}\".", appKey, targetKey), ex);
     }
 }
Exemple #2
0
        public void UpdateInstance(Instance updatedInstance)
        {
            if (updatedInstance == null)
                throw new ArgumentNullException("updatedInstance", "Instance cannot be null.");

            var existingInstance = GetInstance(updatedInstance.Key);
            // Don't allow moving between targets.
            updatedInstance.TargetKey = existingInstance.TargetKey;

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

                        var indexesController = new Internal.Indexes(Context);
                        string indexPath = GetTargetInstancesIndexPath(updatedInstance.TargetKey);
                        indexesController.PutIndexEntry(indexPath, new Internal.EntityIndexEntry() { Key = updatedInstance.Key, Name = updatedInstance.Name });
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed updating instance.", awsEx);
                }
            }
        }
Exemple #3
0
        public void UpdateTarget(Target target)
        {
            if (target == null)
                throw new ArgumentNullException("target", "Target cannot be null.");

            var existingTarget = GetTarget(target.Key);
            // Don't allow moving between groups.
            target.GroupKey = existingTarget.GroupKey;

            using (var stream = target.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        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,
                        })) { }

                        var indexesController = new Internal.Indexes(Context);
                        string indexPath = GetGroupTargetsIndexPath(target.GroupKey);
                        indexesController.PutIndexEntry(indexPath, new Internal.EntityIndexEntry() { Key = target.Key, Name = target.Name });
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed updating target.", awsEx);
                }
            }
        }
Exemple #4
0
        public void UpdateApp(App app)
        {
            if (app == null)
                throw new ArgumentNullException("app", "App cannot be null.");

            var existingApp = GetApp(app.Key);
            // Don't allow moving between groups right now as would have to recursively update references from versions and targets within app.
            app.GroupKey = existingApp.GroupKey;

            using (var stream = app.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var indexesController = new Internal.Indexes(Context);
                        // This will not currently get called.
                        if (existingApp.GroupKey != app.GroupKey)
                        {
                            var groupsController = new Groups(Context);
                            if (!groupsController.GroupExists(app.GroupKey))
                                throw new GroupNotFoundException(string.Format("Group with key \"{0}\" to move app into cannot be found.", app.GroupKey));
                        }
                        using (var putResponse = client.PutObject(new PutObjectRequest()
                        {
                            BucketName = Context.BucketName,
                            Key = string.Format("{0}/{1}/{2}", STR_APPS_CONTAINER_PATH, app.Key.ToString("N"), STR_INFO_FILE_NAME),
                            InputStream = stream,
                        })) { }

                        // This will not currently get called.
                        if (existingApp.GroupKey != app.GroupKey)
                        {
                            string oldAppIndexPath = GetGroupAppsIndexPath(existingApp.GroupKey);
                            indexesController.DeleteIndexEntry(oldAppIndexPath, app.Key);
                        }

                        string newAppIndexPath = GetGroupAppsIndexPath(app.GroupKey);
                        indexesController.PutIndexEntry(newAppIndexPath, new Internal.EntityIndexEntry() { Key = app.Key, Name = app.Name });
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed updating app.", awsEx);
                }
            }
        }
Exemple #5
0
        public void UpdateGroup(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))
                    {
                        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,
                        })) { }

                        var indexesController = new Internal.Indexes(Context);
                        indexesController.PutIndexEntry(STR_GROUP_INDEX_PATH, new Internal.EntityIndexEntry() { Key = group.Key, Name = group.Name });
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed updating group.", awsEx);
                }
            }
        }
Exemple #6
0
        public void UpdateVersion(Version version)
        {
            if (version == null)
                throw new ArgumentNullException("version", "Version cannot be null.");
            if (version.Key == Guid.Empty)
                throw new ArgumentException("Version key cannot be empty.", "version.Key");
            // Disabled these checks as we automatically resolve them for now.
            //if (version.AppKey == Guid.Empty)
            //    throw new ArgumentException("Version app key cannot be empty.", "version.AppKey");
            //if (version.GroupKey == Guid.Empty)
            //    throw new ArgumentException("Version group key cannot be empty.", "version.GroupKey");

            var existingVersion = GetVersion(version.Key);
            // Do not allow moving between apps & groups.
            version.AppKey = existingVersion.AppKey;
            version.GroupKey = existingVersion.GroupKey;

            using (var stream = version.Serialise())
            {
                try
                {
                    using (var client = new AmazonS3Client(Context.AwsAccessKeyId, Context.AwsSecretAccessKey))
                    {
                        var indexesController = new Internal.Indexes(Context);

                        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,
                        })) { }

                        string indexPath = GetAppVersionsIndexPath(version.AppKey);
                        indexesController.PutIndexEntry(indexPath, new Internal.EntityIndexEntry() { Key = version.Key, Name = CreateVersionIndexName(version) }, true);
                    }
                }
                catch (AmazonS3Exception awsEx)
                {
                    throw new DeploymentException("Failed deleting version.", awsEx);
                }
                catch (Exception ex)
                {
                    throw new DeploymentException("Failed deleting version.", ex);
                }
            }
        }