Beispiel #1
0
        public bool IsAttachable(V1ReplicaStatus replica)
        {
            var service = _services.FirstOrDefault(s => s.Replicas.ContainsKey(replica.Name));

            return(service != null &&
                   (service.ServiceType == ServiceType.Project ||
                    service.ServiceType == ServiceType.Function ||
                    service.ServiceType == ServiceType.Executable));
        }
Beispiel #2
0
        private static V1Service CreateServiceJson(Service service)
        {
            var description = service.Description;
            var bindings    = description.Bindings;

            var v1bindingList = new List <V1ServiceBinding>();

            foreach (var binding in bindings)
            {
                v1bindingList.Add(new V1ServiceBinding()
                {
                    Name             = binding.Name,
                    ConnectionString = binding.ConnectionString,
                    Port             = binding.Port,
                    ContainerPort    = binding.ContainerPort,
                    Host             = binding.Host,
                    Protocol         = binding.Protocol
                });
            }

            var v1ConfigurationSourceList = new List <V1ConfigurationSource>();

            foreach (var configSource in description.Configuration)
            {
                v1ConfigurationSourceList.Add(new V1ConfigurationSource()
                {
                    Name  = configSource.Name,
                    Value = configSource.Value
                });
            }

            var v1RunInfo = new V1RunInfo();

            if (description.RunInfo is DockerRunInfo dockerRunInfo)
            {
                v1RunInfo.Type           = V1RunInfoType.Docker;
                v1RunInfo.Image          = dockerRunInfo.Image;
                v1RunInfo.VolumeMappings = dockerRunInfo.VolumeMappings.Select(v => new V1DockerVolume
                {
                    Name   = v.Name,
                    Source = v.Source,
                    Target = v.Target
                }).ToList();

                v1RunInfo.WorkingDirectory = dockerRunInfo.WorkingDirectory;
                v1RunInfo.Args             = dockerRunInfo.Args;
            }
            else if (description.RunInfo is ExecutableRunInfo executableRunInfo)
            {
                v1RunInfo.Type             = V1RunInfoType.Executable;
                v1RunInfo.Args             = executableRunInfo.Args;
                v1RunInfo.Executable       = executableRunInfo.Executable;
                v1RunInfo.WorkingDirectory = executableRunInfo.WorkingDirectory;
            }
            else if (description.RunInfo is ProjectRunInfo projectRunInfo)
            {
                v1RunInfo.Type    = V1RunInfoType.Project;
                v1RunInfo.Args    = projectRunInfo.Args;
                v1RunInfo.Build   = projectRunInfo.Build;
                v1RunInfo.Project = projectRunInfo.ProjectFile.FullName;
            }

            var v1ServiceDescription = new V1ServiceDescription()
            {
                Bindings      = v1bindingList,
                Configuration = v1ConfigurationSourceList,
                Name          = description.Name,
                Replicas      = description.Replicas,
                RunInfo       = v1RunInfo
            };

            var replicateDictionary = new Dictionary <string, V1ReplicaStatus>();

            foreach (var replica in service.Replicas)
            {
                var replicaStatus = new V1ReplicaStatus()
                {
                    Name        = replica.Value.Name,
                    Ports       = replica.Value.Ports,
                    Environment = replica.Value.Environment
                };

                replicateDictionary[replica.Key] = replicaStatus;

                if (replica.Value is ProcessStatus processStatus)
                {
                    replicaStatus.Pid      = processStatus.Pid;
                    replicaStatus.ExitCode = processStatus.ExitCode;
                }
                else if (replica.Value is DockerStatus dockerStatus)
                {
                    replicaStatus.DockerCommand = dockerStatus.DockerCommand;
                    replicaStatus.ContainerId   = dockerStatus.ContainerId;
                }
            }

            var v1Status = new V1ServiceStatus()
            {
                ProjectFilePath  = service.Status.ProjectFilePath,
                ExecutablePath   = service.Status.ExecutablePath,
                Args             = service.Status.Args,
                WorkingDirectory = service.Status.WorkingDirectory,
            };

            var serviceJson = new V1Service()
            {
                ServiceType = service.ServiceType,
                Status      = v1Status,
                Description = v1ServiceDescription,
                Replicas    = replicateDictionary,
                Restarts    = service.Restarts
            };

            return(serviceJson);
        }
Beispiel #3
0
        private static V1Service CreateServiceJson(Service service)
        {
            var description = service.Description;
            var bindings    = description.Bindings;

            var v1BindingList = bindings.Select(binding => new V1ServiceBinding()
            {
                Name             = binding.Name,
                ConnectionString = binding.ConnectionString,
                Port             = binding.Port,
                ContainerPort    = binding.ContainerPort,
                Host             = binding.Host,
                Protocol         = binding.Protocol
            }).ToList();

            var v1ConfigurationSourceList = new List <V1ConfigurationSource>();

            foreach (var(name, value) in description.Configuration)
            {
                v1ConfigurationSourceList.Add(new V1ConfigurationSource()
                {
                    Name  = name,
                    Value = value
                });
            }

            var v1RunInfo = new V1RunInfo();

            switch (description.RunInfo)
            {
            case DockerRunInfo dockerRunInfo:
                v1RunInfo.Type           = V1RunInfoType.Docker;
                v1RunInfo.Image          = dockerRunInfo.Image;
                v1RunInfo.VolumeMappings = dockerRunInfo.VolumeMappings.Select(v => new V1DockerVolume
                {
                    Name   = v.Name,
                    Source = v.Source,
                    Target = v.Target
                }).ToList();

                v1RunInfo.WorkingDirectory = dockerRunInfo.WorkingDirectory;
                v1RunInfo.Args             = dockerRunInfo.Args;
                break;

            case ExecutableRunInfo executableRunInfo:
                v1RunInfo.Type             = V1RunInfoType.Executable;
                v1RunInfo.Args             = executableRunInfo.Args;
                v1RunInfo.Executable       = executableRunInfo.Executable;
                v1RunInfo.WorkingDirectory = executableRunInfo.WorkingDirectory;
                break;

            case ProjectRunInfo projectRunInfo:
                v1RunInfo.Type    = V1RunInfoType.Project;
                v1RunInfo.Args    = projectRunInfo.Args;
                v1RunInfo.Build   = projectRunInfo.Build;
                v1RunInfo.Project = projectRunInfo.ProjectFile.FullName;
                break;
            }

            var v1ServiceDescription = new V1ServiceDescription()
            {
                Bindings      = v1BindingList,
                Configuration = v1ConfigurationSourceList,
                Name          = description.Name,
                Replicas      = description.Replicas,
                RunInfo       = v1RunInfo
            };

            var replicateDictionary = new Dictionary <string, V1ReplicaStatus>();

            foreach (var(instance, replica) in service.Replicas)
            {
                var replicaStatus = new V1ReplicaStatus()
                {
                    Name        = replica.Name,
                    Ports       = replica.Ports,
                    Environment = replica.Environment,
                    State       = replica.State
                };

                replicateDictionary[instance] = replicaStatus;

                switch (replica)
                {
                case ProcessStatus processStatus:
                    replicaStatus.Pid      = processStatus.Pid;
                    replicaStatus.ExitCode = processStatus.ExitCode;
                    break;

                case DockerStatus dockerStatus:
                    replicaStatus.DockerCommand      = dockerStatus.DockerCommand;
                    replicaStatus.ContainerId        = dockerStatus.ContainerId;
                    replicaStatus.DockerNetwork      = dockerStatus.DockerNetwork;
                    replicaStatus.DockerNetworkAlias = dockerStatus.DockerNetworkAlias;
                    break;
                }
            }

            var v1Status = new V1ServiceStatus()
            {
                ProjectFilePath  = service.Status.ProjectFilePath,
                ExecutablePath   = service.Status.ExecutablePath,
                Args             = service.Status.Args,
                WorkingDirectory = service.Status.WorkingDirectory,
            };

            var serviceJson = new V1Service()
            {
                ServiceType = service.ServiceType,
                Status      = v1Status,
                Description = v1ServiceDescription,
                Replicas    = replicateDictionary,
                Restarts    = service.Restarts
            };

            return(serviceJson);
        }
Beispiel #4
0
 public void SetExcludedFromAttachToAll(V1ReplicaStatus replica, bool value)
 {
     _sessionConfiguration.SetAttachToAllEnabled(replica.Name, !value);
 }
Beispiel #5
0
 public bool IsAttachToAllAvailable(V1ReplicaStatus replica)
 {
     return(_sessionConfiguration.IsAttachToAllEnabled(replica.Name));
 }