Example #1
0
        internal virtual CreateRouteResponse CreateRoute(CreateRouteRequest request)
        {
            var marshaller   = CreateRouteRequestMarshaller.Instance;
            var unmarshaller = CreateRouteResponseUnmarshaller.Instance;

            return(Invoke <CreateRouteRequest, CreateRouteResponse>(request, marshaller, unmarshaller));
        }
Example #2
0
        /// <summary>
        /// Creating a Route
        /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/250/routes/creating_a_route.html"</para>
        /// </summary>
        public async Task <CreateRouteResponse> CreateRoute(CreateRouteRequest value)
        {
            UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);

            uriBuilder.Path = "/v2/routes";
            var client = this.GetHttpClient();

            client.Uri    = uriBuilder.Uri;
            client.Method = HttpMethod.Post;
            var authHeader = await BuildAuthenticationHeader();

            if (!string.IsNullOrWhiteSpace(authHeader.Key))
            {
                if (client.Headers.ContainsKey(authHeader.Key))
                {
                    client.Headers[authHeader.Key] = authHeader.Value;
                }
                else
                {
                    client.Headers.Add(authHeader);
                }
            }
            client.ContentType = "application/x-www-form-urlencoded";
            client.Content     = ((string)JsonConvert.SerializeObject(value)).ConvertToStream();
            var expectedReturnStatus = 201;
            var response             = await this.SendAsync(client, expectedReturnStatus);

            return(Utilities.DeserializeJson <CreateRouteResponse>(await response.ReadContentAsStringAsync()));
        }
        public RouteResponse Create(CreateRouteRequest routeRequest)
        {
            var domain       = routeRequest.To <Route>();
            var createdRoute = _routeService.Create(domain);

            AddPlace(new CreateRoutePlaceRequest
            {
                RouteId        = createdRoute.Id,
                PlaceId        = routeRequest.SourceId,
                SequenceNumber = 1
            });

            AddPlace(new CreateRoutePlaceRequest
            {
                RouteId        = createdRoute.Id,
                PlaceId        = routeRequest.DestinationId,
                SequenceNumber = 2
            });

            var routeResponse = createdRoute.To <RouteResponse>();

            routeResponse.Places = _routeService
                                   .ReadPlaces(createdRoute.Id)
                                   .Select(p => p.To <PlaceResponse>()).ToArray();

            return(routeResponse);
        }
Example #4
0
        public bool CreateRouteForRouteTable(
            string peeringConnection,
            string gatewayId,
            string natGatewayId,
            string destinationCidrBlock,
            string routeTableId)
        {
            var request = new CreateRouteRequest();

            if (!string.IsNullOrEmpty(gatewayId))
            {
                request.GatewayId = gatewayId;
            }
            if (!string.IsNullOrEmpty(natGatewayId))
            {
                request.NatGatewayId = natGatewayId;
            }
            if (!string.IsNullOrEmpty(peeringConnection))
            {
                request.VpcPeeringConnectionId = peeringConnection;
            }
            request.DestinationCidrBlock = destinationCidrBlock;
            request.RouteTableId         = routeTableId;

            return(client.CreateRoute(request).Return);
        }
Example #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the CreateRoute operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the CreateRoute operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/appmesh-2018-10-01/CreateRoute">REST API Reference for CreateRoute Operation</seealso>
        public virtual Task <CreateRouteResponse> CreateRouteAsync(CreateRouteRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = CreateRouteRequestMarshaller.Instance;
            var unmarshaller = CreateRouteResponseUnmarshaller.Instance;

            return(InvokeAsync <CreateRouteRequest, CreateRouteResponse>(request, marshaller,
                                                                         unmarshaller, cancellationToken));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the CreateRoute operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the CreateRoute operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/appmesh-2018-10-01/CreateRoute">REST API Reference for CreateRoute Operation</seealso>
        public virtual Task <CreateRouteResponse> CreateRouteAsync(CreateRouteRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = CreateRouteRequestMarshaller.Instance;
            options.ResponseUnmarshaller = CreateRouteResponseUnmarshaller.Instance;

            return(InvokeAsync <CreateRouteResponse>(request, options, cancellationToken));
        }
        internal virtual CreateRouteResponse CreateRoute(CreateRouteRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = CreateRouteRequestMarshaller.Instance;
            options.ResponseUnmarshaller = CreateRouteResponseUnmarshaller.Instance;

            return(Invoke <CreateRouteResponse>(request, options));
        }
Example #8
0
        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());
            }
        }
        private async Task CreateRoute(IAmazonEC2 client, RouteToTransitGateway route)
        {
            var request = new CreateRouteRequest
            {
                DestinationCidrBlock = route.DestinationCidrBlock,
                TransitGatewayId     = route.TransitGatewayId,
                RouteTableId         = route.RouteTableId
            };

            await client.CreateRouteAsync(request);
        }
Example #10
0
        public void CreateRouteTest()
        {
            using (ShimsContext.Create())
            {
                MockClients clients = new MockClients();

                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""
  }
}";
                clients.JsonResponse = json;

                clients.ExpectedStatusCode = (HttpStatusCode)201;
                var cfClient = clients.CreateCloudFoundryClient();

                CreateRouteRequest value = new CreateRouteRequest();


                var obj = cfClient.Routes.CreateRoute(value).Result;


                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);
            }
        }
Example #11
0
        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());
            }
        }
Example #12
0
        public void TestCreateRouteRequest()
        {
            string json = @"{
  ""domain_guid"": ""d97604cc-a5fb-4af2-a9d7-9425bae76aa5"",
  ""space_guid"": ""801f53b3-13e7-4f06-bcb9-545bebb88b29""
}";

            CreateRouteRequest request = new CreateRouteRequest();

            request.DomainGuid = new Guid("d97604cc-a5fb-4af2-a9d7-9425bae76aa5");
            request.SpaceGuid = new Guid("801f53b3-13e7-4f06-bcb9-545bebb88b29");
            string result = JsonConvert.SerializeObject(request, Formatting.None);
            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
Example #13
0
        public void TestCreateRouteRequest()
        {
            string json = @"{
  ""domain_guid"": ""fc7c03f3-a607-4c39-b8d0-0641b5c9d6d0"",
  ""space_guid"": ""6d99b164-3497-4dae-9655-7e869b6b7643""
}";

            CreateRouteRequest request = new CreateRouteRequest();

            request.DomainGuid = new Guid("fc7c03f3-a607-4c39-b8d0-0641b5c9d6d0");
            request.SpaceGuid  = new Guid("6d99b164-3497-4dae-9655-7e869b6b7643");
            string result = JsonConvert.SerializeObject(request, Formatting.None);

            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
        public void TestCreateRouteRequest()
        {
            string json = @"{
  ""domain_guid"": ""238f782a-3b6f-4834-9cda-60eae3ae08ed"",
  ""space_guid"": ""4488d428-cf5d-43bf-a567-e495d8be0348""
}";

            CreateRouteRequest request = new CreateRouteRequest();

            request.DomainGuid = new Guid("238f782a-3b6f-4834-9cda-60eae3ae08ed");
            request.SpaceGuid  = new Guid("4488d428-cf5d-43bf-a567-e495d8be0348");
            string result = JsonConvert.SerializeObject(request, Formatting.None);

            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
Example #15
0
        public void TestCreateRouteRequest()
        {
            string json = @"{
  ""domain_guid"": ""045849ea-d6ab-460f-97c8-a82d990ef44a"",
  ""space_guid"": ""045849ea-d6ab-460f-97c8-a82d990ef44a"",
  ""port"": 10000
}";

            CreateRouteRequest request = new CreateRouteRequest();

            request.DomainGuid = new Guid("045849ea-d6ab-460f-97c8-a82d990ef44a");
            request.SpaceGuid  = new Guid("045849ea-d6ab-460f-97c8-a82d990ef44a");
            request.Port       = 10000;
            string result = JsonConvert.SerializeObject(request, Formatting.None);

            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
Example #16
0
        /// <summary>
        /// Creating a Route
        /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/250/routes/creating_a_route.html"</para>
        /// </summary>
        public async Task <CreateRouteResponse> CreateRoute(CreateRouteRequest value)
        {
            UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);

            uriBuilder.Path = "/v2/routes";
            var client = this.GetHttpClient();

            client.Uri    = uriBuilder.Uri;
            client.Method = HttpMethod.Post;


            client.Content = ((string)JsonConvert.SerializeObject(value)).ConvertToStream();
            var expectedReturnStatus = 201;
            var response             = await this.SendAsync(client, expectedReturnStatus);

            return(Utilities.DeserializeJson <CreateRouteResponse>(await response.Content.ReadAsStringAsync()));
        }
        public void CreateRouteTest()
        {
            using (ShimsContext.Create())
            {
                MockClients clients = new MockClients();

                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""
  }
}";
                clients.JsonResponse = json;

                clients.ExpectedStatusCode = (HttpStatusCode)201;
                var cfClient = clients.CreateCloudFoundryClient();

                CreateRouteRequest value = new CreateRouteRequest();


                var obj = cfClient.Routes.CreateRoute(value).Result;


                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);
            }
        }
Example #18
0
        public void CreateRouteTest()
        {
            using (ShimsContext.Create())
            {
                MockClients clients = new MockClients();

                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""
  }
}";
                clients.JsonResponse = json;

                clients.ExpectedStatusCode = (HttpStatusCode)201;
                var cfClient = clients.CreateCloudFoundryClient();

                CreateRouteRequest value = new CreateRouteRequest();


                var obj = cfClient.Routes.CreateRoute(value).Result;


                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);
            }
        }
Example #19
0
 /// <summary>
 /// Creating a Route
 /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/routes/creating_a_route.html"</para>
 /// </summary>
 public async Task<CreateRouteResponse> CreateRoute(CreateRouteRequest value)
 {
     UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);
     uriBuilder.Path = "/v2/routes";
     var client = this.GetHttpClient();
     client.Uri = uriBuilder.Uri;
     client.Method = HttpMethod.Post;
     var authHeader = await BuildAuthenticationHeader();
     if (!string.IsNullOrWhiteSpace(authHeader.Key))
     {
         client.Headers.Add(authHeader);
     }
     client.ContentType = "application/x-www-form-urlencoded";
     client.Content = JsonConvert.SerializeObject(value).ConvertToStream();
     var expectedReturnStatus = 201;
     var response = await this.SendAsync(client, expectedReturnStatus);
     return Utilities.DeserializeJson<CreateRouteResponse>(await response.ReadContentAsStringAsync());
 }
        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;
                    }
                }
            }
        }
Example #21
0
        public bool load_routetable_id()
        {
            write_log(vpc_id + " のルートデーブルを確認しています。");
            try
            {
                var client    = get_client();
                var query_req = new DescribeRouteTablesRequest();

                query_req.Filters.Add(new Filter()
                {
                    Name = "vpc-id", Values = new List <string>()
                    {
                        vpc_id
                    }
                });
                var query_res = client.DescribeRouteTables(query_req);
                routetable_id = query_res.RouteTables[0].RouteTableId;
                write_log(vpc_id + " のルートデーブルは " + routetable_id + " です");

                foreach (var row in query_res.RouteTables[0].Routes)
                {
                    if (row.GatewayId.Equals(internet_gateway_id) && row.State == RouteState.Active)
                    {
                        return(true);
                    }
                }
                set_name_tag(client, query_res.RouteTables[0].RouteTableId, Helper.build_name(setting_, "rtb"));
                write_log("インターネットゲートウェイ " + internet_gateway_id + " に " + routetable_id + " を関連付けます。");
                var update_req = new CreateRouteRequest();
                update_req.RouteTableId         = routetable_id;
                update_req.DestinationCidrBlock = "0.0.0.0/0";
                update_req.GatewayId            = internet_gateway_id;
                client.CreateRoute(update_req);
            }
            catch (Exception ex)
            {
                write_log("ERROR: " + ex.ToString());
                return(false);
            }
            return(true);
        }
 internal static Task<CreateRouteResponse> CustomCreateRoute(CloudController.V2.Client.Base.AbstractRoutesEndpoint arg1, CreateRouteRequest arg2)
 {
     return Task.Factory.StartNew<CreateRouteResponse>(new Func<CreateRouteResponse>(() => { return new CreateRouteResponse() { EntityMetadata = new Metadata() }; }));
 }
        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, routeInfo.DomainUrl);
                    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;
                    }
                }
            }
        }
Example #24
0
        /// <summary>
        /// Pushes an application to the cloud.
        /// <remarks>
        /// </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");
            var app = await this.Client.AppsExperimental.GetApp(appGuid);

            usedSteps += 1;

            // Step 2 - Create package
            var createPackage   = new Model.Package(appGuid);
            var packageResponse = await this.Client.PackagesExperimental.CreatePackage(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 = 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)
                {
                    var getPackage = await this.Client.PackagesExperimental.GetPackage(packageId);

                    Console.WriteLine(getPackage.state);

                    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;
            }

            var buildResponse = await this.Client.Builds.CreateBuild(packageId);

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

            usedSteps += 1;
            Guid dropLetGuid;

            if (startApplication)
            {
                bool staged = false;
                while (!staged)
                {
                    var getBuild = await this.Client.Builds.GetBuild(buildResponse.guid.Value);

                    Console.WriteLine(getBuild.state);
                    switch (getBuild.state)
                    {
                    case "FAILED":
                    {
                        throw new Exception(string.Format(CultureInfo.InvariantCulture, "Staging failed: {0}", getBuild.error));
                    }

                    case "STAGED":
                    {
                        staged      = true;
                        dropLetGuid = getBuild.droplet.guid.Value;
                        break;
                    }

                    default: continue;
                    }

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

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

                //check droplets..
                using (SimpleHttpClient httpClient = new SimpleHttpClient(this.Client.CancellationToken, new TimeSpan(0, 30, 0), true))
                {
                    httpClient.SkipCertificateValidation = true;

                    httpClient.Headers.Add("Authorization", string.Format("bearer {0}", this.Client.AuthorizationToken));

                    httpClient.Uri    = new Uri($"https://api.system.cf.singel.home/v3/apps/{appGuid}/droplets");
                    httpClient.Method = HttpMethod.Get;

                    //var fap = new { package = new { guid = packageId } };

                    HttpResponseMessage dropResponse = await httpClient.SendAsync();

                    var beun = dropResponse.Content.ReadAsStringAsync().Result;
                }


                // Step 6 - Assign droplet
                //var assignRequest = new AssignDropletAsAppsCurrentDropletRequest(dropLetGuid);
                var assignDroplet = await this.AssignDropletAsAppsCurrentDroplet(appGuid, dropLetGuid);

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

                usedSteps += 1;

                //create route
                var routeRequest = new CreateRouteRequest();
                routeRequest.Host       = "test-route";
                routeRequest.SpaceGuid  = new Guid("ef1c944d-c7ec-4ceb-8177-317130a005da");
                routeRequest.DomainGuid = new Guid("ff8129d7-6304-49da-8345-9c7317ac9d02");
                var routeResponse = await this.Client.V2.Routes.CreateRoute(routeRequest);


                //map route
                // var mapRouteRequest = new MapRouteRequest();
                // mapRouteRequest.RouteGuid = routeResponse.EntityMetadata.Guid;
                await this.Client.V2.Routes.AssociateAppWithRoute(routeResponse.EntityMetadata.Guid, appGuid);


                // Step 7 - Start Application
                var 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 #25
0
 internal static Task <CreateRouteResponse> CustomCreateRoute(CloudController.V2.Client.Base.AbstractRoutesEndpoint arg1, CreateRouteRequest arg2)
 {
     return(Task.Factory.StartNew <CreateRouteResponse>(new Func <CreateRouteResponse>(() => { return new CreateRouteResponse()
                                                                                               {
                                                                                                   EntityMetadata = new Metadata()
                                                                                               }; })));
 }