public async static Task RenameContainer(RenameContainerParameter parameters, IProducer <Null, string> p)
        {
            try {
                CancellationToken cancellation = new CancellationToken();
                await client.Containers.RenameContainerAsync(parameters.ContainerId, new ContainerRenameParameters {
                    NewName = parameters.NewName
                }, cancellation);

                // Updating the containers with the new configurations right away and sending it out
                var updatedContainers = await DockerUpdater.FetchOverviewData();

                var overviewContainerUpdate = DockerUpdater.CreateOverViewData(updatedContainers);
                await KafkaHelpers.SendMessageAsync(DockerUpdater.OverviewTopic, overviewContainerUpdate, p);

                // Send response
                await KafkaHelpers.SendMessageAsync(_responseTopic, new ContainerResponse {
                    ResponseStatusCode = 200,
                    Message            = ResponseMessageContracts.CONTAINER_RENAMED,
                    ContainerIds       = new string[] { parameters.ContainerId }
                }, p);
            } catch (DockerApiException ex) {
                await KafkaHelpers.SendMessageAsync(_responseTopic, new ContainerResponse {
                    ResponseStatusCode = 400,
                    Message            = ex.Message,
                    ContainerIds       = new string[] { parameters.ContainerId }
                }, p);
            }
        }
        public async static Task RefetchOverviewData(IProducer <Null, string> p)
        {
            var updatedContainers = await DockerUpdater.FetchOverviewData();

            var overviewContainerUpdate = DockerUpdater.CreateOverViewData(updatedContainers);
            await KafkaHelpers.SendMessageAsync(DockerUpdater.OverviewTopic, overviewContainerUpdate, p);

            // Send response
            await KafkaHelpers.SendMessageAsync(_responseTopic, new ContainerResponse {
                ResponseStatusCode = 200,
                Message            = ResponseMessageContracts.OVERVIEW_DATA_REFETCHED,
                ContainerIds       = updatedContainers.Select(container => container.Id).ToArray()
            }, p);
        }
        public async static Task RunNewContainer(RunNewContainerParameters parameters, IProducer <Null, string> p)
        {
            try {
                var exposedPorts     = new Dictionary <string, EmptyStruct>();
                var hostPortBindings = new Dictionary <string, IList <PortBinding> >();

                if (parameters.Ports != null)
                {
                    foreach (var portBinding in parameters.Ports)
                    {
                        exposedPorts.Add(portBinding.HostPort, default(EmptyStruct));
                        hostPortBindings.Add(portBinding.ContainerPort, new List <PortBinding> {
                            new PortBinding {
                                HostPort = portBinding.HostPort
                            }
                        });
                    }
                }

                RestartPolicy restartPolicy = new RestartPolicy {
                    Name = RestartPolicyKind.No
                };
                if (parameters.RestartPolicy != null)
                {
                    restartPolicy.MaximumRetryCount = parameters.RestartPolicy.MaximumRetryCount ?? 0;
                    switch (parameters.RestartPolicy.RestartPolicy)
                    {
                    case ContainerRestartPolicy.Always:
                        restartPolicy.Name = RestartPolicyKind.Always;
                        break;

                    case ContainerRestartPolicy.OnFailure:
                        restartPolicy.Name = RestartPolicyKind.OnFailure;
                        break;

                    case ContainerRestartPolicy.UnlessStopped:
                        restartPolicy.Name = RestartPolicyKind.UnlessStopped;
                        break;
                    }
                }
                var environment = new List <string>();
                if (parameters.Environment != null)
                {
                    foreach (var environmentEntry in parameters.Environment)
                    {
                        environment.Add(environmentEntry.Key + "=" + environmentEntry.Value);
                    }
                }
                var volumes = new List <string>();
                if (parameters.Volumes != null)
                {
                    foreach (var volumeEntry in parameters.Volumes)
                    {
                        volumes.Add(volumeEntry.HostPath + ":" + volumeEntry.ContainerPath);
                    }
                }
                var dockerResponse = await client.Containers.CreateContainerAsync(new CreateContainerParameters {
                    Image        = parameters.Image,
                    Cmd          = parameters.Command == null ? null : parameters.Command.Split(" "),
                    Name         = parameters.Name,
                    ExposedPorts = exposedPorts,
                    HostConfig   = new HostConfig {
                        PortBindings    = hostPortBindings,
                        PublishAllPorts = true,
                        RestartPolicy   = restartPolicy,
                        VolumesFrom     = parameters.VolumesFrom,
                        Binds           = volumes,
                        NetworkMode     = parameters.NetworkMode,
                    },
                    Env = environment,
                });

                // Update general info as quickly as possible and send it out so clients can see the newly created container quickly
                var updatedContainers = await DockerUpdater.FetchOverviewData();

                var overviewContainerUpdate = DockerUpdater.CreateOverViewData(updatedContainers);
                await KafkaHelpers.SendMessageAsync(DockerUpdater.OverviewTopic, overviewContainerUpdate, p);

                // Send response
                await KafkaHelpers.SendMessageAsync(_responseTopic, new ContainerResponse {
                    ResponseStatusCode = 201,
                    Message            = ResponseMessageContracts.CONTAINER_CREATED,
                    ContainerIds       = new string[] { dockerResponse.ID }
                }, p);

                await StartContainer(new StartContainerParameters { ContainerId = dockerResponse.ID }, p);
            } catch (DockerApiException ex) {
                await KafkaHelpers.SendMessageAsync(_responseTopic, new ContainerResponse {
                    ResponseStatusCode = 400,
                    Message            = ex.Message,
                    ContainerIds       = null
                }, p); // TODO: create contract for these error messages
            }
        }