Example #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetAppResponse response = new GetAppResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("appSummary", targetDepth))
                {
                    var unmarshaller = AppSummaryUnmarshaller.Instance;
                    response.AppSummary = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("serverGroups", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <ServerGroup, ServerGroupUnmarshaller>(ServerGroupUnmarshaller.Instance);
                    response.ServerGroups = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("tags", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <Tag, TagUnmarshaller>(TagUnmarshaller.Instance);
                    response.Tags = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetAppResponse response = new GetAppResponse();

            var unmarshaller = ApplicationResponseUnmarshaller.Instance;

            response.ApplicationResponse = unmarshaller.Unmarshall(context);

            return(response);
        }
Example #3
0
        public void TestGetAppResponse()
        {
            string json = @"{
  ""guid"": ""guid-4815b14a-47aa-4d80-b391-734a90b9ce96"",
  ""name"": ""my_app"",
  ""desired_state"": ""STOPPED"",
  ""total_desired_instances"": 3,
  ""created_at"": ""2015-06-30T07:10:43Z"",
  ""updated_at"": null,
  ""environment_variables"": {
    ""darkness"": ""ugly""
  },
  ""_links"": {
    ""self"": {
      ""href"": ""/v3/apps/guid-4815b14a-47aa-4d80-b391-734a90b9ce96""
    },
    ""processes"": {
      ""href"": ""/v3/apps/guid-4815b14a-47aa-4d80-b391-734a90b9ce96/processes""
    },
    ""packages"": {
      ""href"": ""/v3/apps/guid-4815b14a-47aa-4d80-b391-734a90b9ce96/packages""
    },
    ""space"": {
      ""href"": ""/v2/spaces/a0e2e437-137c-4000-b02a-1f6095b48056""
    },
    ""desired_droplet"": {
      ""href"": ""/v3/droplets/a-droplet-guid""
    },
    ""start"": {
      ""href"": ""/v3/apps/guid-4815b14a-47aa-4d80-b391-734a90b9ce96/start"",
      ""method"": ""PUT""
    },
    ""stop"": {
      ""href"": ""/v3/apps/guid-4815b14a-47aa-4d80-b391-734a90b9ce96/stop"",
      ""method"": ""PUT""
    },
    ""assign_current_droplet"": {
      ""href"": ""/v3/apps/guid-4815b14a-47aa-4d80-b391-734a90b9ce96/current_droplet"",
      ""method"": ""PUT""
    }
  }
}";

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

            Assert.AreEqual("guid-4815b14a-47aa-4d80-b391-734a90b9ce96", TestUtil.ToTestableString(obj.Guid), true);
            Assert.AreEqual("my_app", TestUtil.ToTestableString(obj.Name), true);
            Assert.AreEqual("STOPPED", TestUtil.ToTestableString(obj.DesiredState), true);
            Assert.AreEqual("3", TestUtil.ToTestableString(obj.TotalDesiredInstances), true);
            Assert.AreEqual("2015-06-30T07:10:43Z", TestUtil.ToTestableString(obj.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true);
        }
Example #4
0
        public GetAppResponse Get(int id)
        {
            var response = new GetAppResponse();
            var app      = _appRepository.Get(id);

            if (app == null)
            {
                response.Exception = new ResourceNotFoundException("App not found.");
            }

            response.App = app?.ToDataContract();

            return(response);
        }
Example #5
0
        public static GetAppResponse Unmarshall(UnmarshallerContext _ctx)
        {
            GetAppResponse getAppResponse = new GetAppResponse();

            getAppResponse.HttpResponse = _ctx.HttpResponse;
            getAppResponse.Code         = _ctx.StringValue("GetApp.Code");
            getAppResponse.Message      = _ctx.StringValue("GetApp.Message");
            getAppResponse.RequestId    = _ctx.StringValue("GetApp.RequestId");

            GetAppResponse.GetApp_Data data = new GetAppResponse.GetApp_Data();
            data.CreatedAt      = _ctx.IntegerValue("GetApp.Data.CreatedAt");
            data.Disabled       = _ctx.StringValue("GetApp.Data.Disabled");
            data.Name           = _ctx.StringValue("GetApp.Data.Name");
            getAppResponse.Data = data;

            return(getAppResponse);
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            GetAppResponse response = new GetAppResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("app", targetDepth))
                {
                    var unmarshaller = AppUnmarshaller.Instance;
                    response.App = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Example #7
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);
        }
Example #8
0
        public void TestGetAppResponse()
        {
            string json = @"{
  ""guid"": ""78586829-1b14-4a92-a21a-19d1761c257c"",
  ""name"": ""my_app"",
  ""desired_state"": ""STOPPED"",
  ""total_desired_instances"": 3,
  ""created_at"": ""2016-07-07T09:16:55Z"",
  ""updated_at"": null,
  ""lifecycle"": {
    ""type"": ""buildpack"",
    ""data"": {
      ""buildpack"": ""name-1210"",
      ""stack"": ""name-1211""
    }
  },
  ""environment_variables"": {
    ""unicorn"": ""horn""
  },
  ""links"": {
    ""self"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5""
    },
    ""space"": {
      ""href"": ""/v2/spaces/d16cf848-de69-4351-8bae-81fb93388b81""
    },
    ""processes"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/processes""
    },
    ""routes"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/routes""
    },
    ""packages"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/packages""
    },
    ""droplet"": {
      ""href"": ""/v3/droplets/a-droplet-guid""
    },
    ""droplets"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/droplets""
    },
    ""start"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/start"",
      ""method"": ""PUT""
    },
    ""stop"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/stop"",
      ""method"": ""PUT""
    },
    ""assign_current_droplet"": {
      ""href"": ""/v3/apps/0aa59813-7efc-4c5c-b7e8-163a086101b5/current_droplet"",
      ""method"": ""PUT""
    }
  }
}";

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

            Assert.AreEqual("78586829-1b14-4a92-a21a-19d1761c257c", TestUtil.ToTestableString(obj.Guid), true);
            Assert.AreEqual("my_app", TestUtil.ToTestableString(obj.Name), true);
            Assert.AreEqual("STOPPED", TestUtil.ToTestableString(obj.DesiredState), true);
            Assert.AreEqual("3", TestUtil.ToTestableString(obj.TotalDesiredInstances), true);
            Assert.AreEqual("2016-07-07T09:16:55Z", TestUtil.ToTestableString(obj.CreatedAt), true);
            Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true);
        }