public void TestCreateRouteResponse() { string json = @"{ ""metadata"": { ""guid"": ""cb4b5237-f79e-431b-a76d-9ee8c0579990"", ""url"": ""/v2/routes/cb4b5237-f79e-431b-a76d-9ee8c0579990"", ""created_at"": ""2016-02-09T10:21:52Z"", ""updated_at"": null }, ""entity"": { ""host"": """", ""domain_guid"": ""fc7c03f3-a607-4c39-b8d0-0641b5c9d6d0"", ""space_guid"": ""6d99b164-3497-4dae-9655-7e869b6b7643"", ""domain_url"": ""/v2/domains/fc7c03f3-a607-4c39-b8d0-0641b5c9d6d0"", ""space_url"": ""/v2/spaces/6d99b164-3497-4dae-9655-7e869b6b7643"", ""apps_url"": ""/v2/routes/cb4b5237-f79e-431b-a76d-9ee8c0579990/apps"" } }"; CreateRouteResponse obj = Utilities.DeserializeJson <CreateRouteResponse>(json); Assert.AreEqual("cb4b5237-f79e-431b-a76d-9ee8c0579990", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true); Assert.AreEqual("/v2/routes/cb4b5237-f79e-431b-a76d-9ee8c0579990", TestUtil.ToTestableString(obj.EntityMetadata.Url), true); Assert.AreEqual("2016-02-09T10:21:52Z", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Host), true); Assert.AreEqual("fc7c03f3-a607-4c39-b8d0-0641b5c9d6d0", TestUtil.ToTestableString(obj.DomainGuid), true); Assert.AreEqual("6d99b164-3497-4dae-9655-7e869b6b7643", TestUtil.ToTestableString(obj.SpaceGuid), true); Assert.AreEqual("/v2/domains/fc7c03f3-a607-4c39-b8d0-0641b5c9d6d0", TestUtil.ToTestableString(obj.DomainUrl), true); Assert.AreEqual("/v2/spaces/6d99b164-3497-4dae-9655-7e869b6b7643", TestUtil.ToTestableString(obj.SpaceUrl), true); Assert.AreEqual("/v2/routes/cb4b5237-f79e-431b-a76d-9ee8c0579990/apps", TestUtil.ToTestableString(obj.AppsUrl), true); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateRouteResponse response = new CreateRouteResponse(); int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth = 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { if (context.TestExpression("return", targetDepth)) { var unmarshaller = BoolUnmarshaller.Instance; response.Return = unmarshaller.Unmarshall(context); continue; } } } return(response); }
public void TestCreateRouteResponse() { string json = @"{ ""metadata"": { ""guid"": ""47de5f7e-9caf-413f-9159-0cdd9ed1fb5a"", ""url"": ""/v2/routes/47de5f7e-9caf-413f-9159-0cdd9ed1fb5a"", ""created_at"": ""2015-04-16T12:04:15+00:00"", ""updated_at"": null }, ""entity"": { ""host"": """", ""domain_guid"": ""238f782a-3b6f-4834-9cda-60eae3ae08ed"", ""space_guid"": ""4488d428-cf5d-43bf-a567-e495d8be0348"", ""domain_url"": ""/v2/domains/238f782a-3b6f-4834-9cda-60eae3ae08ed"", ""space_url"": ""/v2/spaces/4488d428-cf5d-43bf-a567-e495d8be0348"", ""apps_url"": ""/v2/routes/47de5f7e-9caf-413f-9159-0cdd9ed1fb5a/apps"" } }"; CreateRouteResponse obj = Utilities.DeserializeJson <CreateRouteResponse>(json); Assert.AreEqual("47de5f7e-9caf-413f-9159-0cdd9ed1fb5a", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true); Assert.AreEqual("/v2/routes/47de5f7e-9caf-413f-9159-0cdd9ed1fb5a", TestUtil.ToTestableString(obj.EntityMetadata.Url), true); Assert.AreEqual("2015-04-16T12:04:15+00:00", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Host), true); Assert.AreEqual("238f782a-3b6f-4834-9cda-60eae3ae08ed", TestUtil.ToTestableString(obj.DomainGuid), true); Assert.AreEqual("4488d428-cf5d-43bf-a567-e495d8be0348", TestUtil.ToTestableString(obj.SpaceGuid), true); Assert.AreEqual("/v2/domains/238f782a-3b6f-4834-9cda-60eae3ae08ed", TestUtil.ToTestableString(obj.DomainUrl), true); Assert.AreEqual("/v2/spaces/4488d428-cf5d-43bf-a567-e495d8be0348", TestUtil.ToTestableString(obj.SpaceUrl), true); Assert.AreEqual("/v2/routes/47de5f7e-9caf-413f-9159-0cdd9ed1fb5a/apps", TestUtil.ToTestableString(obj.AppsUrl), 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) { CreateRouteResponse response = new CreateRouteResponse(); var unmarshaller = RouteDataUnmarshaller.Instance; response.Route = unmarshaller.Unmarshall(context); return(response); }
public void Route_test() { CreateRouteResponse newRoute = null; UpdateRouteResponse updatedRoute = null; RetrieveRouteResponse retrieveRoute = null; CreateRouteRequest request = new CreateRouteRequest(); request.DomainGuid = domainGuid; request.SpaceGuid = spaceGuid; try { newRoute = client.Routes.CreateRoute(request).Result; } catch (Exception ex) { Assert.Fail("Exception while creating route: {0}", ex.ToString()); } Assert.IsNotNull(newRoute); try { retrieveRoute = client.Routes.RetrieveRoute(newRoute.EntityMetadata.Guid).Result; } catch (Exception ex) { Assert.Fail("Exception while reading route: {0}", ex.ToString()); } Assert.IsNotNull(retrieveRoute); UpdateRouteRequest updateR = new UpdateRouteRequest(); updateR.Host = "newtestdomain"; try { updatedRoute = client.Routes.UpdateRoute(newRoute.EntityMetadata.Guid, updateR).Result; } catch (Exception ex) { Assert.Fail("Exception while updating route: {0}", ex.ToString()); } Assert.IsNotNull(updatedRoute); Assert.AreEqual(updateR.Host, updatedRoute.Host); try { client.Routes.DeleteRoute(newRoute.EntityMetadata.Guid).Wait(); } catch (Exception ex) { Assert.Fail("Exception while deleting space: {0}", ex.ToString()); } }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateRouteResponse response = new CreateRouteResponse(); while (context.Read()) { } return(response); }
private void CreateRoute(CloudFoundryClient client, Guid?spaceGuid, List <string> createdGuid, string host, ListAllDomainsDeprecatedResponse domainInfo) { CreateRouteRequest req = new CreateRouteRequest(); req.DomainGuid = new Guid(domainInfo.EntityMetadata.Guid); req.SpaceGuid = spaceGuid; req.Host = host; try { var routes = client.Routes.ListAllRoutes(new RequestOptions() { Query = string.Format(CultureInfo.InvariantCulture, "host:{0}&domain_guid:{1}", host, domainInfo.EntityMetadata.Guid) }).Result; if (routes.Count() > 0) { ListAllRoutesResponse routeInfo = routes.FirstOrDefault(); Logger.LogMessage("Route {0}.{1} already exists", routeInfo.Host, domainInfo.Name); if (routeInfo != null) { createdGuid.Add(routeInfo.EntityMetadata.Guid); } } else { CreateRouteResponse response = client.Routes.CreateRoute(req).Result; createdGuid.Add(response.EntityMetadata.Guid); } } catch (AggregateException ex) { foreach (Exception e in ex.Flatten().InnerExceptions) { if (e is CloudFoundryException) { Logger.LogWarning(e.Message); } else { throw; } } } }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { CreateRouteResponse response = new CreateRouteResponse(); int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; if (context.IsStartOfDocument) { targetDepth = 2; } while (context.ReadAtDepth(originalDepth)) { if (context.IsStartElement || context.IsAttribute) { } } return(response); }
public void TestCreateRouteResponse() { string json = @"{ ""metadata"": { ""guid"": ""045849ea-d6ab-460f-97c8-a82d990ef44a"", ""url"": ""/v2/routes/750be69a-91e6-4ee5-9009-d1886e0375b4"", ""created_at"": ""2016-09-02T11:52:13Z"", ""updated_at"": null }, ""entity"": { ""host"": """", ""path"": """", ""domain_guid"": ""045849ea-d6ab-460f-97c8-a82d990ef44a"", ""space_guid"": ""045849ea-d6ab-460f-97c8-a82d990ef44a"", ""service_instance_guid"": null, ""port"": 10000, ""domain_url"": ""/v2/shared_domains/8b4b8a1d-644c-410f-8beb-2d7f7a052eb7"", ""space_url"": ""/v2/spaces/46da2a69-5a72-4360-a609-0a33bfbd79d9"", ""apps_url"": ""/v2/routes/750be69a-91e6-4ee5-9009-d1886e0375b4/apps"", ""route_mappings_url"": ""/v2/routes/750be69a-91e6-4ee5-9009-d1886e0375b4/route_mappings"" } }"; CreateRouteResponse obj = Utilities.DeserializeJson <CreateRouteResponse>(json); Assert.AreEqual("045849ea-d6ab-460f-97c8-a82d990ef44a", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true); Assert.AreEqual("/v2/routes/750be69a-91e6-4ee5-9009-d1886e0375b4", TestUtil.ToTestableString(obj.EntityMetadata.Url), true); Assert.AreEqual("2016-09-02T11:52:13Z", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Host), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.Path), true); Assert.AreEqual("045849ea-d6ab-460f-97c8-a82d990ef44a", TestUtil.ToTestableString(obj.DomainGuid), true); Assert.AreEqual("045849ea-d6ab-460f-97c8-a82d990ef44a", TestUtil.ToTestableString(obj.SpaceGuid), true); Assert.AreEqual("", TestUtil.ToTestableString(obj.ServiceInstanceGuid), true); Assert.AreEqual("10000", TestUtil.ToTestableString(obj.Port), true); Assert.AreEqual("/v2/shared_domains/8b4b8a1d-644c-410f-8beb-2d7f7a052eb7", TestUtil.ToTestableString(obj.DomainUrl), true); Assert.AreEqual("/v2/spaces/46da2a69-5a72-4360-a609-0a33bfbd79d9", TestUtil.ToTestableString(obj.SpaceUrl), true); Assert.AreEqual("/v2/routes/750be69a-91e6-4ee5-9009-d1886e0375b4/apps", TestUtil.ToTestableString(obj.AppsUrl), true); Assert.AreEqual("/v2/routes/750be69a-91e6-4ee5-9009-d1886e0375b4/route_mappings", TestUtil.ToTestableString(obj.RouteMappingsUrl), true); }
public void Push(PushArgs pushArgs) { if (!Directory.Exists(pushArgs.Dir)) { throw new DirectoryNotFoundException(string.Format("Directory '{0}' not found", pushArgs.Dir)); } CloudFoundryClient client = SetTargetInfoFromFile(); // ======= GRAB FIRST SPACE AVAILABLE ======= new ConsoleString("Looking up spaces ...", ConsoleColor.Cyan).WriteLine(); PagedResponseCollection <ListAllSpacesResponse> spaces = client.Spaces.ListAllSpaces().Result; if (spaces.Count() == 0) { throw new InvalidOperationException("Couldn't find any spaces"); } ListAllSpacesResponse space = spaces.First(); new ConsoleString(string.Format("Will be using space {0}", space.Name), ConsoleColor.Green).WriteLine(); // ======= CREATE AN APPLICATION ======= new ConsoleString("Creating app ...", ConsoleColor.Cyan).WriteLine(); PagedResponseCollection <ListAllStacksResponse> stacks = client.Stacks.ListAllStacks(new RequestOptions() { Query = string.Format("name:{0}", pushArgs.Stack) }).Result; if (stacks.Count() == 0) { throw new InvalidOperationException(string.Format("Couldn't find the stack {0}", pushArgs.Stack)); } CreateAppRequest createAppRequest = new CreateAppRequest() { Name = pushArgs.Name, Memory = pushArgs.Memory, StackGuid = new Guid(stacks.First().EntityMetadata.Guid), SpaceGuid = new Guid(space.EntityMetadata.Guid) }; CreateAppResponse appCreateResponse = client.Apps.CreateApp(createAppRequest).Result; new ConsoleString(string.Format("Created app with guid '{0}'", appCreateResponse.EntityMetadata.Guid), ConsoleColor.Green).WriteLine(); // ======= CREATE A ROUTE ======= new ConsoleString("Creating a route ...", ConsoleColor.Cyan).WriteLine(); PagedResponseCollection <ListAllSharedDomainsResponse> allDomains = client.SharedDomains.ListAllSharedDomains().Result; if (allDomains.Count() == 0) { throw new InvalidOperationException("Could not find any shared domains"); } string url = string.Format("{0}.{1}", pushArgs.Name, allDomains.First().Name); CreateRouteResponse createRouteResponse = client.Routes.CreateRoute(new CreateRouteRequest() { DomainGuid = new Guid(allDomains.First().EntityMetadata.Guid), Host = pushArgs.Name, SpaceGuid = new Guid(space.EntityMetadata.Guid) }).Result; new ConsoleString(string.Format("Created route '{0}.{1}'", pushArgs.Name, allDomains.First().Name), ConsoleColor.Green).WriteLine(); // ======= BIND THE ROUTE ======= new ConsoleString("Associating the route ...", ConsoleColor.Cyan).WriteLine(); client.Routes.AssociateAppWithRoute( new Guid(createRouteResponse.EntityMetadata.Guid), new Guid(appCreateResponse.EntityMetadata.Guid)).Wait(); // ======= HOOKUP LOGGING ======= // TODO: detect logyard vs loggregator GetV1InfoResponse v1Info = client.Info.GetV1Info().Result; LogyardLog logyard = new LogyardLog(new Uri(v1Info.AppLogEndpoint), string.Format("bearer {0}", client.AuthorizationToken)); logyard.ErrorReceived += (sender, error) => { Program.PrintExceptionMessage(error.Error); }; logyard.StreamOpened += (sender, args) => { new ConsoleString("Log stream opened.", ConsoleColor.Cyan).WriteLine(); }; logyard.StreamClosed += (sender, args) => { new ConsoleString("Log stream closed.", ConsoleColor.Cyan).WriteLine(); }; logyard.MessageReceived += (sender, message) => { new ConsoleString( string.Format("[{0}] - {1}: {2}", message.Message.Value.Source, message.Message.Value.HumanTime, message.Message.Value.Text), ConsoleColor.White).WriteLine(); }; logyard.StartLogStream(appCreateResponse.EntityMetadata.Guid, 0, true); // ======= PUSH THE APP ======= new ConsoleString("Pushing the app ...", ConsoleColor.Cyan).WriteLine(); client.Apps.PushProgress += (sender, progress) => { new ConsoleString(string.Format("Push at {0}%", progress.Percent), ConsoleColor.Yellow).WriteLine(); new ConsoleString(string.Format("{0}", progress.Message), ConsoleColor.DarkYellow).WriteLine(); }; client.Apps.Push(new Guid(appCreateResponse.EntityMetadata.Guid), pushArgs.Dir, true).Wait(); // ======= WAIT FOR APP TO COME ONLINE ======= bool done = false; while (true) { GetAppSummaryResponse appSummary = client.Apps.GetAppSummary(new Guid(appCreateResponse.EntityMetadata.Guid)).Result; if (appSummary.RunningInstances > 0) { break; } if (appSummary.PackageState == "FAILED") { throw new Exception("App staging failed."); } else if (appSummary.PackageState == "PENDING") { new ConsoleString("[cfcmd] - App is staging ...", ConsoleColor.DarkCyan).WriteLine(); } else if (appSummary.PackageState == "STAGED") { new ConsoleString("[cfcmd] - App staged, waiting for it to come online ...", ConsoleColor.DarkCyan).WriteLine(); } Thread.Sleep(2000); } logyard.StopLogStream(); new ConsoleString(string.Format("App is running, done. You can browse it here: http://{0}.{1}", pushArgs.Name, allDomains.First().Name), ConsoleColor.Green).WriteLine(); }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateRouteResponse response = new CreateRouteResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("apiKeyRequired", targetDepth)) { var unmarshaller = BoolUnmarshaller.Instance; response.ApiKeyRequired = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("authorizationScopes", targetDepth)) { var unmarshaller = new ListUnmarshaller <string, StringUnmarshaller>(StringUnmarshaller.Instance); response.AuthorizationScopes = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("authorizationType", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.AuthorizationType = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("authorizerId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.AuthorizerId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("modelSelectionExpression", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ModelSelectionExpression = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("operationName", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.OperationName = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("requestModels", targetDepth)) { var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance); response.RequestModels = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("requestParameters", targetDepth)) { var unmarshaller = new DictionaryUnmarshaller <string, ParameterConstraints, StringUnmarshaller, ParameterConstraintsUnmarshaller>(StringUnmarshaller.Instance, ParameterConstraintsUnmarshaller.Instance); response.RequestParameters = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("routeId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RouteId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("routeKey", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RouteKey = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("routeResponseSelectionExpression", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RouteResponseSelectionExpression = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("target", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Target = 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) { CreateRouteResponse response = new CreateRouteResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("ApplicationId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ApplicationId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Arn", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.Arn = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("CreatedByAccountId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.CreatedByAccountId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("CreatedTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.CreatedTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("LastUpdatedTime", targetDepth)) { var unmarshaller = DateTimeUnmarshaller.Instance; response.LastUpdatedTime = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("OwnerAccountId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.OwnerAccountId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("RouteId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RouteId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("RouteType", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.RouteType = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("ServiceId", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.ServiceId = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("State", targetDepth)) { var unmarshaller = StringUnmarshaller.Instance; response.State = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("Tags", targetDepth)) { var unmarshaller = new DictionaryUnmarshaller <string, string, StringUnmarshaller, StringUnmarshaller>(StringUnmarshaller.Instance, StringUnmarshaller.Instance); response.Tags = unmarshaller.Unmarshall(context); continue; } if (context.TestExpression("UriPathRoute", targetDepth)) { var unmarshaller = UriPathRouteInputUnmarshaller.Instance; response.UriPathRoute = unmarshaller.Unmarshall(context); continue; } } return(response); }