Пример #1
0
        public void TestGetDropletResponse()
        {
            string json = @"{
  ""guid"": ""1a527fb7-0ab7-4b2f-8e90-90f9a51e1941"",
  ""state"": ""STAGED"",
  ""error"": ""example error"",
  ""lifecycle"": {
    ""type"": ""buildpack"",
    ""data"": {
      ""buildpack"": ""name-2441"",
      ""stack"": ""name-2442""
    }
  },
  ""memory_limit"": null,
  ""disk_limit"": null,
  ""result"": {
    ""buildpack"": ""http://buildpack.git.url.com"",
    ""stack"": null,
    ""process_types"": null,
    ""hash"": {
      ""type"": ""sha1"",
      ""value"": null
    },
    ""execution_metadata"": null
  },
  ""environment_variables"": {
    ""cloud"": ""foundry""
  },
  ""created_at"": ""2016-07-07T09:17:17Z"",
  ""updated_at"": null,
  ""links"": {
    ""self"": {
      ""href"": ""/v3/droplets/28722cfd-25ed-4549-b8bd-d95ed61da888""
    },
    ""package"": {
      ""href"": ""/v3/packages/10dbd5a6-b25e-4f19-ba94-122094f4734f""
    },
    ""app"": {
      ""href"": ""/v3/apps/81134907-8a13-497a-ac16-1cbf9c1f9dab""
    },
    ""assign_current_droplet"": {
      ""href"": ""/v3/apps/81134907-8a13-497a-ac16-1cbf9c1f9dab/current_droplet"",
      ""method"": ""PUT""
    }
  }
}";

            GetDropletResponse obj = Utilities.DeserializeJson <GetDropletResponse>(json);

            Assert.AreEqual("1a527fb7-0ab7-4b2f-8e90-90f9a51e1941", TestUtil.ToTestableString(obj.Guid), true);
            Assert.AreEqual("STAGED", TestUtil.ToTestableString(obj.State), true);
            Assert.AreEqual("example error", TestUtil.ToTestableString(obj.Error), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.MemoryLimit), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.DiskLimit), true);
            Assert.AreEqual("2016-07-07T09:17:17Z", TestUtil.ToTestableString(obj.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true);
        }
Пример #2
0
        public void TestGetDropletResponse()
        {
            string json = @"{
  ""guid"": ""guid-b9c83258-f33e-43f0-b0f0-89ad602aa71a"",
  ""state"": ""STAGING"",
  ""hash"": null,
  ""buildpack_git_url"": null,
  ""failure_reason"": ""example failure reason"",
  ""detected_start_command"": ""run -c all_the_things"",
  ""procfile"": null,
  ""environment_variables"": {
    ""cloud"": ""foundry""
  },
  ""created_at"": ""2015-06-30T07:10:59Z"",
  ""updated_at"": null,
  ""_links"": {
    ""self"": {
      ""href"": ""/v3/droplets/guid-b9c83258-f33e-43f0-b0f0-89ad602aa71a""
    },
    ""package"": {
      ""href"": ""/v3/packages/guid-ec95b507-e7d0-4ab8-9dbc-3353a29dfe8c""
    },
    ""app"": {
      ""href"": ""/v3/apps/guid-49fd9afd-a945-45c4-827e-552956a08477""
    }
  }
}";

            GetDropletResponse obj = Utilities.DeserializeJson <GetDropletResponse>(json);

            Assert.AreEqual("guid-b9c83258-f33e-43f0-b0f0-89ad602aa71a", TestUtil.ToTestableString(obj.Guid), true);
            Assert.AreEqual("STAGING", TestUtil.ToTestableString(obj.State), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.Hash), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.BuildpackGitUrl), true);
            Assert.AreEqual("example failure reason", TestUtil.ToTestableString(obj.FailureReason), true);
            Assert.AreEqual("run -c all_the_things", TestUtil.ToTestableString(obj.DetectedStartCommand), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.Procfile), true);
            Assert.AreEqual("2015-06-30T07:10:59Z", TestUtil.ToTestableString(obj.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true);
        }
Пример #3
0
        /// <summary>
        /// Pushes an application to the cloud.
        /// <remarks>
        /// This method is only available on the .NET 4.5 framework.
        /// Calling this method from a Windows Phone App or a Windows App will throw a <see cref="NotImplementedException"/>.
        /// </remarks>
        /// </summary>
        /// <exception cref="NotImplementedException"></exception>
        /// <param name="appGuid">Application guid</param>
        /// <param name="appPath">Path of origin from which the application will be deployed</param>
        /// <param name="stack">The name of the stack the app will be running on</param>
        /// <param name="buildpackGitUrl">Git URL of the buildpack</param>
        /// <param name="startApplication">True if the app should be started after upload is complete, false otherwise</param>
        /// <param name="diskLimit">Memory limit used to stage package</param>
        /// <param name="memoryLimit">Disk limit used to stage package</param>
        public async Task Push(Guid appGuid, string appPath, string stack, string buildpackGitUrl, bool startApplication, int memoryLimit, int diskLimit)
        {
            if (appPath == null)
            {
                throw new ArgumentNullException("appPath");
            }

            IAppPushTools pushTools = new AppPushTools(appPath);
            int           usedSteps = 1;

            // Step 1 - Check if application exists
            this.TriggerPushProgressEvent(usedSteps, "Checking if application exists");
            GetAppResponse app = await this.Client.AppsExperimental.GetApp(appGuid);

            usedSteps += 1;

            // Step 2 - Create package
            CreatePackageRequest createPackage = new CreatePackageRequest();

            createPackage.Type = "bits";
            CreatePackageResponse packageResponse = await this.Client.PackagesExperimental.CreatePackage(appGuid, createPackage);

            Guid packageId = new Guid(packageResponse.Guid.ToString());

            if (this.CheckCancellation())
            {
                return;
            }

            usedSteps += 1;

            // Step 3 - Zip all needed files and get a stream back from the PushTools
            this.TriggerPushProgressEvent(usedSteps, "Creating zip package ...");
            using (Stream zippedPayload = await pushTools.GetZippedPayload(this.Client.CancellationToken))
            {
                if (this.CheckCancellation())
                {
                    return;
                }

                usedSteps += 1;

                // Step 4 - Upload zip to CloudFoundry ...
                this.TriggerPushProgressEvent(usedSteps, "Uploading zip package ...");

                await this.Client.PackagesExperimental.UploadBits(packageId, zippedPayload);

                bool uploadProcessed = false;
                while (!uploadProcessed)
                {
                    GetPackageResponse getPackage = await this.Client.PackagesExperimental.GetPackage(packageId);

                    switch (getPackage.State)
                    {
                    case "FAILED":
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "Upload failed: {0}", getPackage.Data["error"]));
                    }

                    case "READY":
                    {
                        uploadProcessed = true;
                        break;
                    }

                    default: continue;
                    }

                    if (this.CheckCancellation())
                    {
                        return;
                    }

                    Task.Delay(500).Wait();
                }

                usedSteps += 1;
            }

            // Step 5 - Stage application
            StagePackageRequest stagePackage = new StagePackageRequest();

            stagePackage.Lifecycle = new Dictionary <string, dynamic>();
            Dictionary <string, string> data = new Dictionary <string, string>();

            data["buildpack"] = buildpackGitUrl;
            data["stack"]     = stack;
            stagePackage.Lifecycle["data"] = data;
            stagePackage.Lifecycle["type"] = "buildpack";
            stagePackage.MemoryLimit       = memoryLimit;
            stagePackage.DiskLimit         = diskLimit;

            StagePackageResponse stageResponse = await this.Client.PackagesExperimental.StagePackage(packageId, stagePackage);

            if (this.CheckCancellation())
            {
                return;
            }

            usedSteps += 1;
            if (startApplication)
            {
                bool staged = false;
                while (!staged)
                {
                    GetDropletResponse getDroplet = await this.Client.DropletsExperimental.GetDroplet(new Guid(stageResponse.Guid.ToString()));

                    switch (getDroplet.State)
                    {
                    case "FAILED":
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "Staging failed: {0}", getDroplet.Error));
                    }

                    case "STAGED":
                    {
                        staged = true;
                        break;
                    }

                    default: continue;
                    }

                    if (this.CheckCancellation())
                    {
                        return;
                    }

                    Task.Delay(500).Wait();
                }

                // Step 6 - Assign droplet
                AssignDropletAsAppsCurrentDropletRequest assignRequest = new AssignDropletAsAppsCurrentDropletRequest();
                assignRequest.DropletGuid = stageResponse.Guid;
                AssignDropletAsAppsCurrentDropletResponse assignDroplet = await this.AssignDropletAsAppsCurrentDroplet(appGuid, assignRequest);

                if (this.CheckCancellation())
                {
                    return;
                }

                usedSteps += 1;

                // Step 7 - Start Application
                StartingAppResponse response = await this.Client.AppsExperimental.StartingApp(appGuid);

                if (this.CheckCancellation())
                {
                    return;
                }

                usedSteps += 1;
            }

            // Step 8 - Done
            this.TriggerPushProgressEvent(usedSteps, "Application {0} pushed successfully", app.Name);
        }