/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateAppResponse response = new CreateAppResponse(); 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); }
public void UploadInvalidZipTest() { // TODO: use zip with invalid file paths // ref: https://github.com/cloudfoundry/cloud_controller_ng/blob/5b8655ade3ca1b4000a5086101d321c6cfd81ce6/lib/cloud_controller/blobstore/client.rb#L33 var staticContent = "alabala"; var contentPath = Path.Combine(tempAppPath, "content.zip"); File.WriteAllText(contentPath, staticContent); CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; bool exceptionThrown = false; try { using (var fs = File.OpenRead(contentPath)) { client.Apps.UploadBits(appGuid, fs, new List <Common.PushTools.FileFingerprint>()).Wait(); } } catch (Exception ex) { exceptionThrown = true; Assert.IsInstanceOfType(ex.InnerException, typeof(CloudFoundryException)); Assert.IsTrue(ex.InnerException.Message.Contains("uploading bits")); } Assert.IsTrue(exceptionThrown); client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
public void Application_test() { CreateAppResponse newApp = null; GetAppSummaryResponse readApp = null; UpdateAppResponse updateApp = null; CreateAppRequest app = new CreateAppRequest(); app.Name = Guid.NewGuid().ToString(); app.SpaceGuid = spaceGuid; app.Instances = 1; app.Memory = 256; app.StackGuid = stackGuid; try { newApp = client.Apps.CreateApp(app).Result; } catch (Exception ex) { Assert.Fail("Error creating app: {0}", ex.ToString()); } Assert.IsNotNull(newApp); try { readApp = client.Apps.GetAppSummary(newApp.EntityMetadata.Guid).Result; } catch (Exception ex) { Assert.Fail("Error reading app: {0}", ex.ToString()); } Assert.IsNotNull(readApp); Assert.AreEqual(app.Name, readApp.Name); UpdateAppRequest updateAppRequest = new UpdateAppRequest(); updateAppRequest.Memory = 512; try { updateApp = client.Apps.UpdateApp(newApp.EntityMetadata.Guid, updateAppRequest).Result; } catch (Exception ex) { Assert.Fail("Error updating app: {0}", ex.ToString()); } Assert.IsNotNull(updateApp); Assert.AreEqual(updateAppRequest.Memory, updateApp.Memory); try { client.Apps.DeleteApp(newApp.EntityMetadata.Guid).Wait(); } catch (Exception ex) { Assert.Fail("Error deleting app: {0}", ex.ToString()); } }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateAppResponse response = new CreateAppResponse(); context.Read(); UnmarshallResult(context, response); return(response); }
public void LogsTest() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, appPath, true).Wait(); while (true) { var instances = client.Apps.GetInstanceInformationForStartedApp(appGuid).Result; if (instances.Count > 0) { if (instances[0].State.ToLower() == "running") { break; } } } var logyardClient = new LogyardLog( new Uri(client.Info.GetV1Info().Result.AppLogEndpoint), string.Format("bearer {0}", client.AuthorizationToken), null, true); var logs = new List <string>(); logyardClient.MessageReceived += delegate(object sender, MessageEventArgs e) { Assert.IsTrue(string.IsNullOrEmpty(e.Message.Error)); logs.Add(e.Message.Value.Text); }; logyardClient.ErrorReceived += delegate(object sender, Logyard.Client.ErrorEventArgs e) { Assert.Fail("Logyard error: {0}", e.Error.ToString()); }; EventWaitHandle stopevent = new EventWaitHandle(false, EventResetMode.ManualReset); logyardClient.StreamClosed += delegate { stopevent.Set(); }; logyardClient.StartLogStream(appGuid.ToString(), 100, false); stopevent.WaitOne(); var conatainsPushedContent = logs.Any((line) => line.Contains("dummy content")); Assert.IsTrue(conatainsPushedContent, "Pushed content was not dumped in the output stream"); var conatainsEnvContent = logs.Any((line) => line.Contains("env-test-1234")); Assert.IsTrue(conatainsEnvContent, "Pushed env variable was not dumped in the output stream"); client.Apps.DeleteApp(appGuid).Wait(); }
public void LoggregatorRecentTest() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, tempAppPath, true).Wait(); while (true) { var appSummary = client.Apps.GetAppSummary(appGuid).Result; var packageState = appSummary.PackageState.ToLowerInvariant(); if (packageState != "pending") { Assert.AreEqual("staged", packageState); var instances = client.Apps.GetInstanceInformationForStartedApp(appGuid).Result; if (instances.Count > 0) { if (instances[0].State.ToLower() == "running") { break; } } } } if (client.Info.GetInfo().Result.LoggingEndpoint == null) { Assert.Inconclusive("CloudFoundry target does not have a loggregator endpoint"); } var logClient = new LoggregatorLog( new Uri(client.Info.GetInfo().Result.LoggingEndpoint), string.Format("bearer {0}", client.AuthorizationToken), null, true); // Just wait a bit to get the latest logs Thread.Sleep(1000); var appLogs = logClient.Recent(appGuid.ToString(), CancellationToken.None).Result; var conatainsPushedContent = appLogs.Any((line) => line.Message.Contains("dummy content")); Assert.IsTrue(conatainsPushedContent, "Pushed content was not dumped in the output stream: {0}", string.Join(Environment.NewLine, appLogs.Select(x => x.Message))); var conatainsEnvContent = appLogs.Any((line) => line.Message.Contains("envtest1234")); Assert.IsTrue(conatainsEnvContent, "Pushed env variable was not dumped in the output stream: {0}", string.Join(Environment.NewLine, appLogs.Select(x => x.Message))); client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateAppResponse response = new CreateAppResponse(); var unmarshaller = ApplicationResponseUnmarshaller.Instance; response.ApplicationResponse = unmarshaller.Unmarshall(context); return(response); }
public static CreateAppResponse Unmarshall(UnmarshallerContext _ctx) { CreateAppResponse createAppResponse = new CreateAppResponse(); createAppResponse.HttpResponse = _ctx.HttpResponse; createAppResponse.RequestId = _ctx.StringValue("CreateApp.requestId"); createAppResponse.Result = _ctx.StringValue("CreateApp.result"); return(createAppResponse); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateAppResponse response = new CreateAppResponse(); context.Read(); response.CreateAppResult = CreateAppResultUnmarshaller.GetInstance().Unmarshall(context); return(response); }
public static CreateAppResponse Unmarshall(UnmarshallerContext context) { CreateAppResponse createAppResponse = new CreateAppResponse(); createAppResponse.HttpResponse = context.HttpResponse; createAppResponse.RequestId = context.StringValue("CreateApp.RequestId"); createAppResponse.Data = context.StringValue("CreateApp.Data"); return(createAppResponse); }
public void PushJobTest() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, appPath, true).Wait(); client.Apps.DeleteApp(appGuid).Wait(); }
public void UploadTwiceTest() { var staticContent = "alabala"; var contentPath = Path.Combine(tempAppPath, "content.zip"); using (var fs = File.OpenWrite(contentPath)) { using (var za = new ZipArchive(fs, ZipArchiveMode.Create, true)) { var ze = za.CreateEntry("content.txt", CompressionLevel.NoCompression); using (var sw = new StreamWriter(ze.Open())) { sw.Write(staticContent); } } } CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; using (var fs = File.OpenRead(contentPath)) { client.Apps.UploadBits(appGuid, fs, new List <FileFingerprint>() { }).Wait(); } using (var fs = File.OpenRead(contentPath)) { client.Apps.UploadBits(appGuid, fs, new List <FileFingerprint>() { }).Wait(); } var zipFromServerPath = Path.GetTempFileName(); DownloadAppZip(appGuid.ToString(), zipFromServerPath); if (new FileInfo(zipFromServerPath).Length == 0) { Assert.Inconclusive("API endpoint doesn't support package downloads"); } using (var fs = File.OpenRead(zipFromServerPath)) { using (var arch = new ZipArchive(fs, ZipArchiveMode.Read, true)) { Assert.IsTrue(arch.Entries.Count() == 1); Assert.IsTrue(arch.Entries.First(a => a.Name == "content.txt").Length == staticContent.Length); } } client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
public static CreateAppResponse Unmarshall(UnmarshallerContext context) { CreateAppResponse createAppResponse = new CreateAppResponse() { HttpResponse = context.HttpResponse, RequestId = context.StringValue("CreateApp.RequestId"), AppKey = context.LongValue("CreateApp.AppKey") }; return(createAppResponse); }
public void UploadTestWithCache() { var staticContent = "dummy content"; var content1 = Guid.NewGuid().ToString(); Directory.CreateDirectory(Path.Combine(tempAppPath, "f1")); Directory.CreateDirectory(Path.Combine(tempAppPath, "c1")); File.WriteAllText(Path.Combine(tempAppPath, "f1\\content.txt"), staticContent); // https://github.com/cloudfoundry/cf-release/blob/master/jobs/cloud_controller_ng/spec#L242 long binContentSize = 65536 * 3; using (FileStream stream = new FileStream(Path.Combine(tempAppPath, "c1\\bigcontent.bin"), FileMode.Create)) { var rng = new Random(); using (BinaryWriter writer = new BinaryWriter(stream)) { while (writer.BaseStream.Length < binContentSize) { writer.Write((byte)rng.Next(256)); } writer.Close(); } } CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, tempAppPath, false).Wait(); // Push twice to use the cache client.Apps.Push(appGuid, tempAppPath, false).Wait(); var zipFromServerPath = Path.GetTempFileName(); DownloadAppZip(appGuid.ToString(), zipFromServerPath); if (new FileInfo(zipFromServerPath).Length == 0) { Assert.Inconclusive("API endpoint doesn't support package downloads"); } using (var fs = File.OpenRead(zipFromServerPath)) { using (var arch = new ZipArchive(fs, ZipArchiveMode.Read, true)) { Assert.IsTrue(arch.Entries.First(a => a.FullName == "f1/content.txt").Length == staticContent.Length); Assert.IsTrue(arch.Entries.First(a => a.FullName == "c1/bigcontent.bin").Length == binContentSize); } } client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
public static CreateAppResponse Unmarshall(UnmarshallerContext context) { CreateAppResponse createAppResponse = new CreateAppResponse(); createAppResponse.HttpResponse = context.HttpResponse; createAppResponse.RequestId = context.StringValue("CreateApp.RequestId"); createAppResponse.AppId = context.LongValue("CreateApp.AppId"); createAppResponse.TagStatus = context.BooleanValue("CreateApp.TagStatus"); return(createAppResponse); }
public void PushJobTest() { apprequest.Name = "simplePushTest" + Guid.NewGuid().ToString("N"); CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, appPath, true).Wait(); client.Apps.DeleteApp(appGuid).Wait(); }
public void UploadTest() { var staticContent = "dummy content"; var content1 = Guid.NewGuid().ToString(); var content2 = Guid.NewGuid().ToString(); Directory.CreateDirectory(Path.Combine(tempAppPath, "f1")); Directory.CreateDirectory(Path.Combine(tempAppPath, "f1", "f2")); File.WriteAllText(Path.Combine(tempAppPath, "content.txt"), staticContent); File.WriteAllText(Path.Combine(tempAppPath, "content-clone.txt"), staticContent); File.WriteAllText(Path.Combine(tempAppPath, "f1\\content.txt"), staticContent); File.WriteAllText(Path.Combine(tempAppPath, "f1\\f2\\content-in-folder.txt"), staticContent); File.WriteAllText(Path.Combine(tempAppPath, "content-Unique.txt"), content1); File.WriteAllText(Path.Combine(tempAppPath, "content-unique-clone.txt"), content1); File.WriteAllText(Path.Combine(tempAppPath, "content-unique2.txt"), content2); File.WriteAllText(Path.Combine(tempAppPath, "zero.txt"), ""); File.WriteAllText(Path.Combine(tempAppPath, "zero2.txt"), ""); CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, tempAppPath, false).Wait(); var zipFromServerPath = Path.GetTempFileName(); DownloadAppZip(appGuid.ToString(), zipFromServerPath); if (new FileInfo(zipFromServerPath).Length == 0) { Assert.Inconclusive("API endpoint doesn't support package downloads"); } using (var fs = File.OpenRead(zipFromServerPath)) { using (var arch = new ZipArchive(fs, ZipArchiveMode.Read, true)) { Assert.AreEqual(9, arch.Entries.Count()); Assert.IsTrue(arch.Entries.First(a => a.FullName == "content.txt").Length == staticContent.Length); Assert.IsTrue(arch.Entries.First(a => a.FullName == "zero.txt").Length == 0); Assert.IsTrue(arch.Entries.First(a => a.Name == "content-in-folder.txt").FullName == "f1/f2/content-in-folder.txt"); var contentSStream = new StreamReader(arch.Entries.First(a => a.Name == "content-Unique.txt").Open()); Assert.IsTrue(contentSStream.ReadToEnd() == content1); } } client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
public void TestCreateAppResponse() { string json = @"{ ""guid"": ""d158f2f9-ed4a-428b-a5a8-eb59d7ac4788"", ""name"": ""my_app"", ""desired_state"": ""STOPPED"", ""total_desired_instances"": 0, ""created_at"": ""2015-06-30T07:10:43Z"", ""updated_at"": null, ""environment_variables"": { ""open"": ""source"" }, ""_links"": { ""self"": { ""href"": ""/v3/apps/d158f2f9-ed4a-428b-a5a8-eb59d7ac4788"" }, ""processes"": { ""href"": ""/v3/apps/d158f2f9-ed4a-428b-a5a8-eb59d7ac4788/processes"" }, ""packages"": { ""href"": ""/v3/apps/d158f2f9-ed4a-428b-a5a8-eb59d7ac4788/packages"" }, ""space"": { ""href"": ""/v2/spaces/7f257247-1447-47cd-8791-5066b6574499"" }, ""start"": { ""href"": ""/v3/apps/d158f2f9-ed4a-428b-a5a8-eb59d7ac4788/start"", ""method"": ""PUT"" }, ""stop"": { ""href"": ""/v3/apps/d158f2f9-ed4a-428b-a5a8-eb59d7ac4788/stop"", ""method"": ""PUT"" }, ""assign_current_droplet"": { ""href"": ""/v3/apps/d158f2f9-ed4a-428b-a5a8-eb59d7ac4788/current_droplet"", ""method"": ""PUT"" } } }"; CreateAppResponse obj = Utilities.DeserializeJson <CreateAppResponse>(json); Assert.AreEqual("d158f2f9-ed4a-428b-a5a8-eb59d7ac4788", TestUtil.ToTestableString(obj.Guid), true); Assert.AreEqual("my_app", TestUtil.ToTestableString(obj.Name), true); Assert.AreEqual("STOPPED", TestUtil.ToTestableString(obj.DesiredState), true); Assert.AreEqual("0", TestUtil.ToTestableString(obj.TotalDesiredInstances), true); Assert.AreEqual("2015-06-30T07:10:43Z", TestUtil.ToTestableString(obj.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.UpdatedAt), true); }
public static CreateAppResponse Unmarshall(UnmarshallerContext _ctx) { CreateAppResponse createAppResponse = new CreateAppResponse(); createAppResponse.HttpResponse = _ctx.HttpResponse; createAppResponse.RequestId = _ctx.StringValue("CreateApp.RequestId"); createAppResponse.Code = _ctx.IntegerValue("CreateApp.Code"); createAppResponse.ErrMsg = _ctx.StringValue("CreateApp.ErrMsg"); CreateAppResponse.CreateApp_Result result = new CreateAppResponse.CreateApp_Result(); result.AppId = _ctx.LongValue("CreateApp.Result.AppId"); createAppResponse.Result = result; return(createAppResponse); }
public void DoublePush() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; client.Apps.Push(app.EntityMetadata.Guid, appPath, false).Wait(); UpdateAppRequest updateApp = new UpdateAppRequest(); updateApp.Name = app.Name; updateApp.Memory = 512; updateApp.Instances = 1; UpdateAppResponse updatedApp = client.Apps.UpdateApp(app.EntityMetadata.Guid, updateApp).Result; client.Apps.Push(app.EntityMetadata.Guid, appPath, false).Wait(); client.Apps.DeleteApp(app.EntityMetadata.Guid).Wait(); }
public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateAppResponse response = new CreateAppResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("AppId", targetDepth)) { response.AppId = StringUnmarshaller.GetInstance().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) { CreateAppResponse response = new CreateAppResponse(); 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); }
public static CreateAppResponse Unmarshall(UnmarshallerContext _ctx) { CreateAppResponse createAppResponse = new CreateAppResponse(); createAppResponse.HttpResponse = _ctx.HttpResponse; createAppResponse.Code = _ctx.StringValue("CreateApp.Code"); createAppResponse.Message = _ctx.StringValue("CreateApp.Message"); createAppResponse.RequestId = _ctx.StringValue("CreateApp.RequestId"); CreateAppResponse.CreateApp_Data data = new CreateAppResponse.CreateApp_Data(); data.CreatedAt = _ctx.StringValue("CreateApp.Data.CreatedAt"); data.CreatorName = _ctx.StringValue("CreateApp.Data.CreatorName"); data.Disabled = _ctx.BooleanValue("CreateApp.Data.Disabled"); data.Id = _ctx.StringValue("CreateApp.Data.Id"); data.Name = _ctx.StringValue("CreateApp.Data.Name"); createAppResponse.Data = data; return(createAppResponse); }
private static async Task Main() { Console.WriteLine("Press Any Key"); Console.ReadKey(); var securityToken = await GetSecurityToken() .ConfigureAwait(false); CreateAppResponse app = await CreateApp(securityToken) .ConfigureAwait(false); var import = await PostFile(securityToken, app.Body.App.AppId) .ConfigureAwait(false); await Export(securityToken, import.Body.Document.DocId) .ConfigureAwait(false); Console.WriteLine("Done"); Console.ReadKey(); }
private static void UnmarshallResult(JsonUnmarshallerContext context, CreateAppResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; while (context.Read()) { if (context.TestExpression("AppId", targetDepth)) { context.Read(); response.AppId = StringUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.CurrentDepth <= originalDepth) { return; } } return; }
public void PushWithReadonlyFilesTest() { var tmpPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tmpPath); var tmpReadonlyFile = Path.Combine(tmpPath, "readonly.txt"); File.WriteAllText(tmpReadonlyFile, "contenttt"); apprequest.Name = "readonylPushTest" + Guid.NewGuid().ToString("N"); CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; File.SetAttributes(tmpReadonlyFile, FileAttributes.ReadOnly); client.Apps.Push(appGuid, tmpPath, false).Wait(); File.SetAttributes(tmpReadonlyFile, ~FileAttributes.ReadOnly); Directory.Delete(tmpPath, true); client.Apps.DeleteApp(appGuid).Wait(); }
public IActionResult Create([FromForm] CreateAppRequest createRequest) { if (string.IsNullOrEmpty(Request.Headers[SecurityToken.X_CSRF_TOKEN])) { return(Unauthorized()); } CreateAppResponse response = new CreateAppResponse() { Header = new Header { Status = new Status { Code = Status.SUCCESS } }, Body = new CreateAppResponseBody { App = new App { AppId = Guid.NewGuid().ToString(), ApplicationName = "EditAreaTextParagraph", ApplicationOI = "3", ApplicationPath = string.Empty, DatabaseId = Guid.NewGuid().ToString(), EditorVersion = createRequest.EditorVersion ?? "1.1.0.7948", EngineVersion = "900101", PackageCreationDate = DateTime.Now, PackageFile = "ExstreamPackage.pub", PackageVersion = "900122", PreviewPubFile = createRequest.PreviewPubFile, RoleNames = createRequest.RoleName ?? new List <string>() } } }; return(new OkObjectResult(response)); }
public override bool Execute() { this.CFOrganization = this.CFOrganization.Trim(); this.CFSpace = this.CFSpace.Trim(); var app = LoadAppFromManifest(); this.Logger = new TaskLogger(this); CloudFoundryClient client = InitClient(); Guid?spaceGuid = null; Guid?stackGuid = null; try { if ((!string.IsNullOrWhiteSpace(this.CFSpace)) && (!string.IsNullOrWhiteSpace(this.CFOrganization))) { spaceGuid = Utils.GetSpaceGuid(client, this.Logger, this.CFOrganization, this.CFSpace); if (spaceGuid == null) { return(false); } } if (!string.IsNullOrWhiteSpace(app.StackName)) { PagedResponseCollection <ListAllStacksResponse> stackList = client.Stacks.ListAllStacks().Result; var stackInfo = stackList.Where(o => o.Name == app.StackName).FirstOrDefault(); if (stackInfo == null) { Logger.LogError("Stack {0} not found", app.StackName); return(false); } stackGuid = new Guid(stackInfo.EntityMetadata.Guid); } if (stackGuid.HasValue && spaceGuid.HasValue) { PagedResponseCollection <ListAllAppsForSpaceResponse> apps = client.Spaces.ListAllAppsForSpace(spaceGuid, new RequestOptions() { Query = "name:" + app.Name }).Result; if (apps.Count() > 0) { this.CFAppGuid = apps.FirstOrDefault().EntityMetadata.Guid; UpdateAppRequest request = new UpdateAppRequest(); request.SpaceGuid = spaceGuid; request.StackGuid = stackGuid; request.EnvironmentJson = app.EnvironmentVariables; request.Memory = (int)app.Memory; request.Instances = app.InstanceCount; request.Buildpack = app.BuildpackUrl; request.Command = app.Command; if (app.DiskQuota.HasValue) { request.DiskQuota = app.DiskQuota.Value.ToString(System.Globalization.CultureInfo.InvariantCulture); } UpdateAppResponse response = client.Apps.UpdateApp(new Guid(this.CFAppGuid), request).Result; Logger.LogMessage("Updated app {0} with guid {1}", response.Name, response.EntityMetadata.Guid); } else { CreateAppRequest request = new CreateAppRequest(); request.Name = app.Name; request.SpaceGuid = spaceGuid; request.StackGuid = stackGuid; request.EnvironmentJson = app.EnvironmentVariables; request.Memory = (int)app.Memory; request.Instances = app.InstanceCount; request.Buildpack = app.BuildpackUrl; request.Command = app.Command; if (app.DiskQuota.HasValue) { request.DiskQuota = Convert.ToInt32(app.DiskQuota.Value, System.Globalization.CultureInfo.InvariantCulture); } CreateAppResponse response = client.Apps.CreateApp(request).Result; this.CFAppGuid = response.EntityMetadata.Guid; Logger.LogMessage("Created app {0} with guid {1}", app.Name, this.CFAppGuid); } } } catch (Exception exception) { this.Logger.LogError("Create App failed", exception); return(false); } return(true); }
public void LoggregatorTailTest() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; if (client.Info.GetInfo().Result.LoggingEndpoint == null) { Assert.Inconclusive("CloudFoundry target does not have a loggregator endpoint"); } var logClient = new LoggregatorLog( new Uri(client.Info.GetInfo().Result.LoggingEndpoint), string.Format("bearer {0}", client.AuthorizationToken), null, true); var logs = new List <string>(); logClient.MessageReceived += delegate(object sender, MessageEventArgs e) { long timeInMilliSeconds = e.LogMessage.Timestamp / 1000 / 1000; var logTimeStamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(timeInMilliSeconds); logs.Add(String.Format("[{0}] - {1}: {2}", e.LogMessage.SourceName, logTimeStamp.ToString(), e.LogMessage.Message)); }; logClient.ErrorReceived += delegate(object sender, CloudFoundry.Loggregator.Client.ErrorEventArgs e) { Assert.Fail("Loggregator error: {0}", e.Error.ToString()); }; logClient.Tail(appGuid.ToString()); client.Apps.Push(appGuid, tempAppPath, true).Wait(); while (true) { var appSummary = client.Apps.GetAppSummary(appGuid).Result; var packageState = appSummary.PackageState.ToLowerInvariant(); if (packageState != "pending") { Assert.AreEqual("staged", packageState); var instances = client.Apps.GetInstanceInformationForStartedApp(appGuid).Result; if (instances.Count > 0) { if (instances[0].State.ToLower() == "running") { break; } } } } // Just wait a bit to get the latest logs Thread.Sleep(1000); logClient.StopLogStream(); var conatainsPushedContent = logs.Any((line) => line.Contains("dummy content")); Assert.IsTrue(conatainsPushedContent, "Pushed content was not dumped in the output stream: {0}", string.Join(Environment.NewLine, logs)); var conatainsEnvContent = logs.Any((line) => line.Contains("envtest1234")); Assert.IsTrue(conatainsEnvContent, "Pushed env variable was not dumped in the output stream: {0}", string.Join(Environment.NewLine, logs)); client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }
public void LogyardRecentTest() { CreateAppResponse app = client.Apps.CreateApp(apprequest).Result; Guid appGuid = app.EntityMetadata.Guid; client.Apps.Push(appGuid, tempAppPath, true).Wait(); while (true) { var appSummary = client.Apps.GetAppSummary(appGuid).Result; var packageState = appSummary.PackageState.ToLowerInvariant(); if (packageState != "pending") { Assert.AreEqual(packageState, "staged"); var instances = client.Apps.GetInstanceInformationForStartedApp(appGuid).Result; if (instances.Count > 0) { if (instances[0].State.ToLower() == "running") { break; } } } } if (client.Info.GetV1Info().Result.AppLogEndpoint == null) { Assert.Inconclusive("CloudFoundry target does not have a logyard endpoint"); } var logyardClient = new LogyardLog( new Uri(client.Info.GetV1Info().Result.AppLogEndpoint), string.Format("bearer {0}", client.AuthorizationToken), null, true); var logs = new List <string>(); logyardClient.MessageReceived += delegate(object sender, MessageEventArgs e) { Assert.IsTrue(string.IsNullOrEmpty(e.Message.Error)); logs.Add(e.Message.Value.Text); }; logyardClient.ErrorReceived += delegate(object sender, Logyard.Client.ErrorEventArgs e) { Assert.Fail("Logyard error: {0}", e.Error.ToString()); }; var stopevent = new EventWaitHandle(false, EventResetMode.ManualReset); logyardClient.StreamClosed += delegate { stopevent.Set(); }; // Just wait a bit to get the latest logs Thread.Sleep(1000); logyardClient.StartLogStream(appGuid.ToString(), 100, false); stopevent.WaitOne(); var conatainsPushedContent = logs.Any((line) => line.Contains("dummy content")); Assert.IsTrue(conatainsPushedContent, "Pushed content was not dumped in the output stream: {0}", string.Join(Environment.NewLine, logs)); var conatainsEnvContent = logs.Any((line) => line.Contains("env-test-1234")); Assert.IsTrue(conatainsEnvContent, "Pushed env variable was not dumped in the output stream: {0}", string.Join(Environment.NewLine, logs)); client.Apps.DeleteApp(appGuid).Wait(); Directory.Delete(tempAppPath, true); }