Example #1
0
        public Container(
            string id,
            string handle,
            IContainerUser user,
            IContainerDirectory directory,
            IContainerPropertyService propertyService,
            ILocalTcpPortManager tcpPortManager,
            JobObject jobObject,
            DiskQuotaControl diskQuotaControl,
            IProcessRunner processRunner,
            IProcessRunner constrainedProcessRunner,
            ProcessHelper processHelper,
            Dictionary<string, string> defaultEnvironment,
            ContainerHostDependencyHelper dependencyHelper
            )
        {
            this.id = id;
            this.handle = handle;
            this.user = user;
            this.directory = directory;
            this.propertyService = propertyService;
            this.tcpPortManager = tcpPortManager;
            this.jobObject = jobObject;
            this.diskQuotaControl = diskQuotaControl;
            this.processRunner = processRunner;
            this.constrainedProcessRunner = constrainedProcessRunner;
            this.processHelper = processHelper;
            this.dependencyHelper = dependencyHelper;
            this.defaultEnvironment = defaultEnvironment ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

            this.currentState = ContainerState.Active;
        }
Example #2
0
        public Container()
        {
            this.handle = new ContainerHandle();
            this.user = new ContainerUser(handle, shouldCreate: true);
            this.directory = new ContainerDirectory(this.handle, this.user, true);
            this.state = ContainerState.Born;

            this.processManager = new ProcessManager(this.user);
        }
Example #3
0
        private static bool IsContainerRunning(ContainerState state)
        {
            if (state.Running)
            {
                return(true);
            }

            if (!string.IsNullOrEmpty(state.FinishedAt))
            {
                // container exited early?
                throw new InvalidOperationException("Container.Abstractions has exited with code: " + state.ExitCode);
            }

            // still starting, I guess...
            return(false);
        }
Example #4
0
        public static NMContainerStatus NewInstance(ContainerId containerId, ContainerState
                                                    containerState, Resource allocatedResource, string diagnostics, int containerExitStatus
                                                    , Priority priority, long creationTime)
        {
            NMContainerStatus status = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <NMContainerStatus
                                                                                      >();

            status.SetContainerId(containerId);
            status.SetContainerState(containerState);
            status.SetAllocatedResource(allocatedResource);
            status.SetDiagnostics(diagnostics);
            status.SetContainerExitStatus(containerExitStatus);
            status.SetPriority(priority);
            status.SetCreationTime(creationTime);
            return(status);
        }
Example #5
0
        /// <exception cref="System.Exception"/>
        public virtual NodeHeartbeatResponse NodeHeartbeat(ApplicationAttemptId attemptId
                                                           , long containerId, ContainerState containerState)
        {
            Dictionary <ApplicationId, IList <Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus
                                              > > nodeUpdate = new Dictionary <ApplicationId, IList <Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus
                                                                                                     > >(1);

            Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus containerStatus = BuilderUtils
                                                                                 .NewContainerStatus(BuilderUtils.NewContainerId(attemptId, containerId), containerState
                                                                                                     , "Success", 0);
            AList <Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus> containerStatusList = new
                                                                                             AList <Org.Apache.Hadoop.Yarn.Api.Records.ContainerStatus>(1);

            containerStatusList.AddItem(containerStatus);
            Org.Mortbay.Log.Log.Info("ContainerStatus: " + containerStatus);
            nodeUpdate[attemptId.GetApplicationId()] = containerStatusList;
            return(NodeHeartbeat(nodeUpdate, true));
        }
Example #6
0
 private void HandleGroupChange()
 {
     //kalo grup IsSet == true, dan stock penuh,
     //cek lokasi. Kalo beda dengan needleLocation dan tujuannya juga bukan needle location,
     //alihkan tujuan
     if (this.group.IsSet)
     {
         if (this.Stock != 0)
         {
             if ((this.Location != this.group.NeedleLocation) && (this.PointInfo != this.group.NeedleLocation))
             {
                 this.StopMoving();
                 this.containerState     = ContainerState.JalanBiasa;
                 group.ActiveDestination = group.NeedleLocation;
                 this.MoveTo(Global.PF.FindWay(this.Location, this.group.ActiveDestination).Points);
             }
         }
     }
 }
Example #7
0
        private ContainerState CreateContainerState(Warehouse warehouse, Container c, DateTimeOffset date)
        {
            var            now            = DateTimeOffset.Now;
            ContainerState containerState = new ContainerState()
            {
                Id           = c.Id,
                Description  = c.Description,
                LastDetected = date,
                MovedTo      = date,
                Number       = c.Number,
                Type         = c.Type,
                WarehouseId  = warehouse.Id,
                Weight       = c.Weight,
                Status       = now.Subtract(date).TotalMinutes < 1 ? Enums.ContainerStatus.Online : Enums.ContainerStatus.Expired
            };

            _containers.AddOrUpdate(containerState.Id, containerState, (id, oldCs) => containerState);
            return(containerState);
        }
Example #8
0
        public void Clear()
        {
            Stop();
            if (VideoWindow != null)
            {
                VideoWindow.Visible = 0;
            }

            FileValid    = false;
            TestControl  = null;
            MediaControl = null;
            VideoWindow  = null;
            FilterGraph  = null;
            if (omsdFileName != null)
            {
                System.IO.File.Delete(omsdFileName);
                FileValid = false;
            }
            State = ContainerState.CS_Empty;
        }
        public IsRunningStartupCheckStrategyTest()
        {
            _mockContainerId = "my_container_id";

            var dockerClientMock = new DockerClientMock();

            _dockerClientMock = dockerClientMock.MockDockerClient;

            var mockInspectResponse = new ContainerInspectResponse();

            dockerClientMock.MockContainerOperations.Setup(e => e.InspectContainerAsync(
                                                               _mockContainerId,
                                                               default(CancellationToken)))
            .Returns(Task.FromResult(mockInspectResponse));

            _containerStateMock       = new ContainerState();
            mockInspectResponse.State = _containerStateMock;

            _strategy = new IsRunningStartupCheckStrategy();
        }
Example #10
0
        public static ServiceRunningState ToServiceState(this ContainerState state)
        {
            if (null == state)
            {
                return(ServiceRunningState.Unknown);
            }

            if (state.Running)
            {
                return(ServiceRunningState.Running);
            }

            if (state.Dead)
            {
                return(ServiceRunningState.Stopped);
            }

            if (state.Restarting)
            {
                return(ServiceRunningState.Starting);
            }

            if (state.Paused)
            {
                return(ServiceRunningState.Paused);
            }

            var status = state.Status?.ToLower() ?? string.Empty;

            if (status == "created")
            {
                return(ServiceRunningState.Stopped);
            }

            if (status == "exited")
            {
                return(ServiceRunningState.Stopped);
            }

            return(ServiceRunningState.Unknown);
        }
Example #11
0
        public void Destroy()
        {
            lock (_ioLock)
            {
                Stop(true);
                StopGuardAndWait(new TimeSpan(0, 0, 0, 10));


                foreach (var port in reservedPorts)
                {
                    tcpPortManager.ReleaseLocalPort(port, user.UserName);
                }
                tcpPortManager.RemoveFirewallRules(user.UserName);

                // BR - Unmap the mounted directories (Removes user ACLs)
                try
                {
                    jobObject.TerminateProcessesAndWait();
                }
                catch (ObjectDisposedException)
                {
                }
                jobObject.Dispose();

                if (directory != null)
                {
                    directory.Destroy();
                }

                deleteUserDiskQuota();

                if (user != null)
                {
                    user.Delete();
                }

                this.currentState = ContainerState.Destroyed;
            }
        }
Example #12
0
        public void Destroy()
        {
            lock (_ioLock)
            {
                LogCompletionStatus();

                Stop(true);
                StopGuardAndWait(new TimeSpan(0, 0, 0, 10));

                foreach (var port in reservedPorts)
                {
                    tcpPortManager.ReleaseLocalPort(port, user.UserName);
                }
                tcpPortManager.RemoveFirewallRules(user.UserName);

                try
                {
                    jobObject.TerminateProcessesAndWait();
                }
                catch (ObjectDisposedException)
                {
                }
                jobObject.Dispose();

                directory.Destroy();

                if (user != null)
                {
                    directory.DeleteBindMounts(bindMounts, user);
                    user.DeleteProfile();
                    user.Delete();
                }

                deleteUserDiskQuota();

                this.currentState = ContainerState.Destroyed;
            }
        }
Example #13
0
 public ContainerInfo(ContainerReport container)
 {
     // JAXB needs this
     containerId = container.GetContainerId().ToString();
     if (container.GetAllocatedResource() != null)
     {
         allocatedMB     = container.GetAllocatedResource().GetMemory();
         allocatedVCores = container.GetAllocatedResource().GetVirtualCores();
     }
     if (container.GetAssignedNode() != null)
     {
         assignedNodeId = container.GetAssignedNode().ToString();
     }
     priority            = container.GetPriority().GetPriority();
     startedTime         = container.GetCreationTime();
     finishedTime        = container.GetFinishTime();
     elapsedTime         = Times.Elapsed(startedTime, finishedTime);
     diagnosticsInfo     = container.GetDiagnosticsInfo();
     logUrl              = container.GetLogUrl();
     containerExitStatus = container.GetContainerExitStatus();
     containerState      = container.GetContainerState();
     nodeHttpAddress     = container.GetNodeHttpAddress();
 }
Example #14
0
        /// <summary>
        /// Used for restore.
        /// </summary>
        private Container(string handle, ContainerState containerState)
        {
            if (handle.IsNullOrWhiteSpace())
            {
                throw new ArgumentNullException("handle");
            }
            this.handle = new ContainerHandle(handle);

            if (containerState == null)
            {
                throw new ArgumentNullException("containerState");
            }
            this.state = containerState;

            this.user = new ContainerUser(handle);
            this.directory = new ContainerDirectory(this.handle, this.user);

            this.processManager = new ProcessManager(this.user);

            if (this.state == ContainerState.Active)
            {
                this.RestoreProcesses();
            }
        }
Example #15
0
        static ModuleStatus ToRuntimeStatus(ContainerState containerState)
        {
            ModuleStatus status;

            switch (containerState.Status.ToLower())
            {
            case "created":
            case "paused":
            case "restarting":
                status = ModuleStatus.Stopped;
                break;

            case "removing":
            case "exited":
                // if the exit code is anything other than zero then the container is
                // considered as having "failed"; otherwise it is considered as stopped
                status = containerState.ExitCode == 0 ? ModuleStatus.Stopped : ModuleStatus.Failed;
                break;

            case "dead":
                status = ModuleStatus.Dead;
                break;

            case "running":
                status = ModuleStatus.Running;
                break;

            default:
                // TODO: What exactly does this state mean? Maybe we should just throw?
                Events.InvalidContainerStatusFound(containerState.Status);
                status = ModuleStatus.Unknown;
                break;
            }

            return(status);
        }
Example #16
0
        public void Run()
        {
            if (!((State == ContainerState.CS_Connected) || (State == ContainerState.CS_Stopped)))
            {
                return;
            }
            if ((TestControl == null) || (MediaControl == null))
            {
                throw new VideoException("Internal error in AV engine");
            }
            Exception ex        = null;
            Action    RunAction = new Action(() =>
            {
                try
                {
                    TestControl.ControlStream(1);
                    MediaControl.Run();
                    State = ContainerState.CS_Running;
                }
                catch (Exception e)
                {
                    ex = e;
                }
            });
            IAsyncResult RunResult = RunAction.BeginInvoke(null, null);

            if (RTSP)
            {
                ProceedAction(6, 8, RunResult, ref ex);
            }
            else
            {
                // skip SETUP and PLAY steps
                ProceedAction(8, 8, RunResult, ref ex);
            }
        }
Example #17
0
        public static ContainerFinishData NewInstance(ContainerId containerId, long finishTime
                                                      , string diagnosticsInfo, int containerExitCode, ContainerState containerState)
        {
            ContainerFinishData containerFD = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <ContainerFinishData
                                                                                             >();

            containerFD.SetContainerId(containerId);
            containerFD.SetFinishTime(finishTime);
            containerFD.SetDiagnosticsInfo(diagnosticsInfo);
            containerFD.SetContainerExitStatus(containerExitCode);
            containerFD.SetContainerState(containerState);
            return(containerFD);
        }
Example #18
0
        public void Destroy()
        {
            lock (_ioLock)
            {
                Stop(true);
                StopGuardAndWait(new TimeSpan(0, 0, 0, 10));

                foreach (var port in reservedPorts)
                {
                    tcpPortManager.ReleaseLocalPort(port, user.UserName);
                }
                tcpPortManager.RemoveFirewallRules(user.UserName);

                // BR - Unmap the mounted directories (Removes user ACLs)
                try
                {
                    jobObject.TerminateProcessesAndWait();
                }
                catch (ObjectDisposedException)
                {
                }
                jobObject.Dispose();

                if (directory != null)
                    directory.Destroy();

                deleteUserDiskQuota();

                if (user != null)
                    user.Delete();

                this.currentState = ContainerState.Destroyed;
            }
        }
Example #19
0
 public virtual void SetContainerState(ContainerState containerState)
 {
     this.containerState = containerState;
 }
Example #20
0
        public void DoNext(Player _player)
        {
            //inisiasi list azn point
            if (first)
            {
                first = false;
                foreach (VG.Map.Entity e in _player.Tissue.get_EntitiesByType(VG.Map.EntityEnum.AZN))
                {
                    aznPoint.Add(new Point(e.X, e.Y));
                }
            }

            //alokasi grup
            if (this.group == null)
            {
                for (int i = 0; i < MyAI.arrGroup.Length; i++)
                {
                    if (MyAI.arrGroup[i].CountContainer < 2)
                    {
                        this.group = MyAI.arrGroup[i];
                        //MyAI.arrGroup[i].CountContainer += 1;
                        MyAI.arrGroup[i].Container.Add(this);
                        break;
                    }
                }
            }
            if (this.group == null) // kalo masih null juga -> bot baru dibuat setelah salah satu hancur
            {
                foreach (NanoBot bot in _player.NanoBots)
                {
                    if (bot is ContainerBot)
                    {
                        ((ContainerBot)bot).group = null;   // reset grup
                    }
                    if ((bot is NeedleBot) && (((NeedleBot)bot).Stock < 100))
                    {
                        Global.HPList.Add(bot.Location);
                    }
                }
                for (int i = 0; i < MyAI.arrGroup.Length; i++)
                {
//                    for (int j = 0; j < MyAI.arrGroup[i].Container.Count; j++)
//                    //foreach (ContainerBot bot in MyAI.arrGroup[i].Container)
//                    {
//                        if (((ContainerBot)MyAI.arrGroup[i].Container[j]).HitPoint <= 0)
//                        {
//                            ContainerBot tmpBot = (ContainerBot)MyAI.arrGroup[i].Container[3 - j];
                            MyAI.arrGroup[i].Container = new ArrayList();
//                            if (tmpBot.HitPoint > 0)
//                            {
//                                MyAI.arrGroup[i].Container.Add(tmpBot);
//                            }
                            MyAI.arrGroup[i].Done = true;
                            MyAI.arrGroup[i].IsSet = false;
                            MyAI.arrGroup[i].NeedleLocation = Point.Empty;
//                            break;
//                        }
//                    }
                }
                return;
            }

            HandleDefendingGuard();
            HandleStockKosong();
            HandleGroupChange();
            HandleAIChangeDirection();
            HandleEmptyNeedle();

            #region ContainerBot's logic
            if (this.State == NanoBotState.WaitingOrders)
            {
                if ((!this.group.IsSet) || (group.Done))
                {
                    // cek jika ada Needle di HPList
                    //if (Global.HPList.Count > 0)
                    //{
                    //    this.group.IsSet = true;
                    //    this.group.Done = false;
                    //    this.group.NeedleLocation = (Point)Global.HPList[0];
                    //    Global.HPList.RemoveAt(0);
                    //    //this.containerState = ContainerState.Transfer;
                    //    return;
                    //}
                    //else
                        if (group.ActiveDestination != _player.AI.Location)
                        {
                            group.ActiveDestination = _player.AI.Location;
                        }
                        this.MoveTo(Global.PF.FindWay(this.Location, group.ActiveDestination).Points);
                }
                else
                {
                    this.StopMoving();
                    this.containerState = ContainerState.Transfer;
                    if (this.Location.Equals(this.group.NeedleLocation))
                    {
                        this.TransferTo(this.group.NeedleLocation, 10);
                    }
                    else
                    {
                        if (group.ActiveDestination != group.NeedleLocation)
                        {
                            group.ActiveDestination = group.NeedleLocation;
                        }
                        this.MoveTo(Global.PF.FindWay(this.Location, this.group.ActiveDestination).Points);
                    }
                    return;
                }
            }
            #endregion
        }
 private YarnProtos.ContainerStateProto ConvertToProtoFormat(ContainerState state)
 {
     return(ProtoUtils.ConvertToProtoFormat(state));
 }
Example #22
0
 private void ChangeState(ContainerState containerState)
 {
     rwlock.EnterWriteLock();
     try
     {
         this.state = containerState;
     }
     finally
     {
         rwlock.ExitWriteLock();
     }
 }
Example #23
0
 private void HandleStockKosong()
 {
     if (this.Stock < this.ContainerCapacity)
     {
         this.containerState = ContainerState.Ngisi;
         // find AZN destination
         Point dest = Point.Empty;
         //Point azn1 = Global.FindClosest(EntityEnum.AZN, this.Location, this.NanoBotType);
         //Point azn2 = Global.FindClosest(EntityEnum.AZN, Global.MYAI.AI.Location, this.NanoBotType);
         //if (this.group.IsSet)
         //{
         //    dest = Global.FindClosest(EntityEnum.AZN, this.group.NeedleLocation, this.NanoBotType);
         //}
         //else
         //{
             dest = Global.FindClosest(EntityEnum.AZN, this.Location, this.NanoBotType);
         //}
         if (this.Location != dest)
         {
             if (this.PointInfo != dest)
             {
                 this.StopMoving();
                 group.ActiveDestination = Global.FindClosest(EntityEnum.AZN, this.Location, this.NanoBotType);
                 this.MoveTo(Global.PF.FindWay(this.Location, group.ActiveDestination).Points);
             }
         }
         else
         {
             this.StopMoving();
             group.ActiveDestination = Point.Empty;
             this.CollectFrom(this.Location, 10);
             this.containerState = ContainerState.JalanBiasa;
         }
     }
 }
Example #24
0
    // Update is called once per frame
    void Update()
    {
        if(this.state != this.oldState)
        {
            if(this.state == ContainerState.Idle)
            {
                directioner.localFrom = Vector3.forward;
                directioner.to = Vector3.up;
            }
            else if(this.state == ContainerState.Picked)
            {
                directioner.localFrom = Vector3.forward;
                directioner.to = Vector3.up;
            }
            else if(this.state == ContainerState.Pouring)
            {
                this.positioner.targetPosition = this.pouringPosition;
                this.positioner.enabled = true;
                this.GetComponent<Rigidbody>().isKinematic = true;
            }
            else if(this.state == ContainerState.Returned)
            {
                this.objectDragger.Detach();
            }

            if(this.state != ContainerState.Pouring)
            {
                this.positioner.enabled = false;
                this.GetComponent<Rigidbody>().isKinematic = false;
            }

            this.oldState = this.state;
        }

        if(this.state == ContainerState.Picked)
        {
            objectDragger.Drag();
        }

        if(this.state == ContainerState.Pouring)
        {
            directioner.localFrom = Vector3.forward;
            directioner.to = Vector3.Normalize(tubeTip - this.transform.position);

            if(!this.sound.isPlaying)
                this.sound.Play();

            filledTube.Fill();

            if(filledTube.isFilled())
            {
                this.state = ContainerState.Picked;
                this.sound.Stop();
            }
        }
    }
        private static ContainerReport ConvertToContainerReport(TimelineEntity entity, string
                                                                serverHttpAddress, string user)
        {
            int            allocatedMem             = 0;
            int            allocatedVcore           = 0;
            string         allocatedHost            = null;
            int            allocatedPort            = -1;
            int            allocatedPriority        = 0;
            long           createdTime              = 0;
            long           finishedTime             = 0;
            string         diagnosticsInfo          = null;
            int            exitStatus               = ContainerExitStatus.Invalid;
            ContainerState state                    = null;
            string         nodeHttpAddress          = null;
            IDictionary <string, object> entityInfo = entity.GetOtherInfo();

            if (entityInfo != null)
            {
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedMemoryEntityInfo))
                {
                    allocatedMem = (int)entityInfo[ContainerMetricsConstants.AllocatedMemoryEntityInfo
                                   ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedVcoreEntityInfo))
                {
                    allocatedVcore = (int)entityInfo[ContainerMetricsConstants.AllocatedVcoreEntityInfo
                                     ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedHostEntityInfo))
                {
                    allocatedHost = entityInfo[ContainerMetricsConstants.AllocatedHostEntityInfo].ToString
                                        ();
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedPortEntityInfo))
                {
                    allocatedPort = (int)entityInfo[ContainerMetricsConstants.AllocatedPortEntityInfo
                                    ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedPriorityEntityInfo))
                {
                    allocatedPriority = (int)entityInfo[ContainerMetricsConstants.AllocatedPriorityEntityInfo
                                        ];
                }
                if (entityInfo.Contains(ContainerMetricsConstants.AllocatedHostHttpAddressEntityInfo
                                        ))
                {
                    nodeHttpAddress = (string)entityInfo[ContainerMetricsConstants.AllocatedHostHttpAddressEntityInfo
                                      ];
                }
            }
            IList <TimelineEvent> events = entity.GetEvents();

            if (events != null)
            {
                foreach (TimelineEvent @event in events)
                {
                    if (@event.GetEventType().Equals(ContainerMetricsConstants.CreatedEventType))
                    {
                        createdTime = @event.GetTimestamp();
                    }
                    else
                    {
                        if (@event.GetEventType().Equals(ContainerMetricsConstants.FinishedEventType))
                        {
                            finishedTime = @event.GetTimestamp();
                            IDictionary <string, object> eventInfo = @event.GetEventInfo();
                            if (eventInfo == null)
                            {
                                continue;
                            }
                            if (eventInfo.Contains(ContainerMetricsConstants.DiagnosticsInfoEventInfo))
                            {
                                diagnosticsInfo = eventInfo[ContainerMetricsConstants.DiagnosticsInfoEventInfo].ToString
                                                      ();
                            }
                            if (eventInfo.Contains(ContainerMetricsConstants.ExitStatusEventInfo))
                            {
                                exitStatus = (int)eventInfo[ContainerMetricsConstants.ExitStatusEventInfo];
                            }
                            if (eventInfo.Contains(ContainerMetricsConstants.StateEventInfo))
                            {
                                state = ContainerState.ValueOf(eventInfo[ContainerMetricsConstants.StateEventInfo
                                                               ].ToString());
                            }
                        }
                    }
                }
            }
            NodeId      allocatedNode = NodeId.NewInstance(allocatedHost, allocatedPort);
            ContainerId containerId   = ConverterUtils.ToContainerId(entity.GetEntityId());
            string      logUrl        = WebAppUtils.GetAggregatedLogURL(serverHttpAddress, allocatedNode.
                                                                        ToString(), containerId.ToString(), containerId.ToString(), user);

            return(ContainerReport.NewInstance(ConverterUtils.ToContainerId(entity.GetEntityId
                                                                                ()), Resource.NewInstance(allocatedMem, allocatedVcore), NodeId.NewInstance(allocatedHost
                                                                                                                                                            , allocatedPort), Priority.NewInstance(allocatedPriority), createdTime, finishedTime
                                               , diagnosticsInfo, logUrl, exitStatus, state, nodeHttpAddress));
        }
Example #26
0
 protected virtual void OnStateChanged(ContainerState obj)
 {
     StateChanged?.Invoke(obj);
 }
Example #27
0
 public static ContainerState ConvertFromProtoFormat(YarnProtos.ContainerStateProto
                                                     e)
 {
     return(ContainerState.ValueOf(e.ToString().Replace(ContainerStatePrefix, string.Empty
                                                        )));
 }
Example #28
0
 /*
  * ContainerState
  */
 public static YarnProtos.ContainerStateProto ConvertToProtoFormat(ContainerState
                                                                   e)
 {
     return(YarnProtos.ContainerStateProto.ValueOf(ContainerStatePrefix + e.ToString()
                                                   ));
 }
Example #29
0
 public abstract void SetContainerState(ContainerState containerState);
Example #30
0
        public void DoNext(Player _player)
        {
            //inisiasi list azn point
            if (first)
            {
                first = false;
                foreach (VG.Map.Entity e in _player.Tissue.get_EntitiesByType(VG.Map.EntityEnum.AZN))
                {
                    aznPoint.Add(new Point(e.X, e.Y));
                }
            }

            //alokasi grup
            if (this.group == null)
            {
                for (int i = 0; i < MyAI.arrGroup.Length; i++)
                {
                    if (MyAI.arrGroup[i].CountContainer < 2)
                    {
                        this.group = MyAI.arrGroup[i];
                        //MyAI.arrGroup[i].CountContainer += 1;
                        MyAI.arrGroup[i].Container.Add(this);
                        break;
                    }
                }
            }
            if (this.group == null) // kalo masih null juga -> bot baru dibuat setelah salah satu hancur
            {
                foreach (NanoBot bot in _player.NanoBots)
                {
                    if (bot is ContainerBot)
                    {
                        ((ContainerBot)bot).group = null;   // reset grup
                    }
                    if ((bot is NeedleBot) && (((NeedleBot)bot).Stock < 100))
                    {
                        Global.HPList.Add(bot.Location);
                    }
                }
                for (int i = 0; i < MyAI.arrGroup.Length; i++)
                {
//                    for (int j = 0; j < MyAI.arrGroup[i].Container.Count; j++)
//                    //foreach (ContainerBot bot in MyAI.arrGroup[i].Container)
//                    {
//                        if (((ContainerBot)MyAI.arrGroup[i].Container[j]).HitPoint <= 0)
//                        {
//                            ContainerBot tmpBot = (ContainerBot)MyAI.arrGroup[i].Container[3 - j];
                    MyAI.arrGroup[i].Container = new ArrayList();
//                            if (tmpBot.HitPoint > 0)
//                            {
//                                MyAI.arrGroup[i].Container.Add(tmpBot);
//                            }
                    MyAI.arrGroup[i].Done           = true;
                    MyAI.arrGroup[i].IsSet          = false;
                    MyAI.arrGroup[i].NeedleLocation = Point.Empty;
//                            break;
//                        }
//                    }
                }
                return;
            }

            HandleDefendingGuard();
            HandleStockKosong();
            HandleGroupChange();
            HandleAIChangeDirection();
            HandleEmptyNeedle();

            #region ContainerBot's logic
            if (this.State == NanoBotState.WaitingOrders)
            {
                if ((!this.group.IsSet) || (group.Done))
                {
                    // cek jika ada Needle di HPList
                    //if (Global.HPList.Count > 0)
                    //{
                    //    this.group.IsSet = true;
                    //    this.group.Done = false;
                    //    this.group.NeedleLocation = (Point)Global.HPList[0];
                    //    Global.HPList.RemoveAt(0);
                    //    //this.containerState = ContainerState.Transfer;
                    //    return;
                    //}
                    //else
                    if (group.ActiveDestination != _player.AI.Location)
                    {
                        group.ActiveDestination = _player.AI.Location;
                    }
                    this.MoveTo(Global.PF.FindWay(this.Location, group.ActiveDestination).Points);
                }
                else
                {
                    this.StopMoving();
                    this.containerState = ContainerState.Transfer;
                    if (this.Location.Equals(this.group.NeedleLocation))
                    {
                        this.TransferTo(this.group.NeedleLocation, 10);
                    }
                    else
                    {
                        if (group.ActiveDestination != group.NeedleLocation)
                        {
                            group.ActiveDestination = group.NeedleLocation;
                        }
                        this.MoveTo(Global.PF.FindWay(this.Location, this.group.ActiveDestination).Points);
                    }
                    return;
                }
            }
            #endregion
        }
Example #31
0
 public virtual void SetState(ContainerState state)
 {
     this.state = state;
 }
Example #32
0
        public void Destroy()
        {
            rwlock.EnterWriteLock();
            try
            {
                processManager.StopProcesses(); // NB: do this first to unlock files.

                if (port != null)
                {
                    port.Delete(user);
                }

                directory.Delete();

                user.Delete();

                this.state = ContainerState.Destroyed;
            }
            finally
            {
                rwlock.ExitWriteLock();
            }
        }
Example #33
0
 private void HandleGroupChange()
 {
     //kalo grup IsSet == true, dan stock penuh,
     //cek lokasi. Kalo beda dengan needleLocation dan tujuannya juga bukan needle location,
     //alihkan tujuan
     if (this.group.IsSet)
     {
         if (this.Stock != 0)
         {
             if ((this.Location != this.group.NeedleLocation) && (this.PointInfo != this.group.NeedleLocation))
             {
                 this.StopMoving();
                 this.containerState = ContainerState.JalanBiasa;
                 group.ActiveDestination = group.NeedleLocation;
                 this.MoveTo(Global.PF.FindWay(this.Location, this.group.ActiveDestination).Points);
             }
         }
     }
 }
Example #34
0
 public static Container Restore(string handle, ContainerState containerState)
 {
     return new Container(handle, containerState);
 }
Example #35
0
 /// <exception cref="System.Exception"/>
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 public static void WaitForContainerState(ContainerManagementProtocol containerManager
                                          , ContainerId containerID, ContainerState finalState)
 {
     WaitForContainerState(containerManager, containerID, finalState, 20);
 }
Example #36
0
        private void DoCommand(
            bool condition, Action commandAction, int stepFrom, int stepTo,
            Action successAction, ContainerState successState, int stepToSetState)
        {
            if (!condition)
            {
                return;
            }
            if ((TestControl == null) || (MediaControl == null))
            {
                throw new VideoException("Internal error in AV engine");
            }
            Exception ex            = null;
            Action    CommandAction = new Action(() =>
            {
                try
                {
                    commandAction();
                }
                catch (Exception e)
                {
                    ex = e;
                }
            });

            OMSDIO ini = new OMSDIO(omsdFileName);

            ini.WriteString("Test State", "StepEnded", "0");
            int MsgFirst = ini.GetMessageCount() + 1;

            int StepEnded = 0;
            int LogStep   = stepFrom;
            int StepState = 0;
            int MsgCurr   = ini.GetMessageCount() + 1;

            IAsyncResult Result = CommandAction.BeginInvoke(null, null);

            try
            {
                DateTime Till = DateTime.Now.AddSeconds(Timeout / 1000);
                if (EventConsumer != null)
                {
                    EventConsumer.FireBeginStep(StepNames[LogStep]);

                    while (StepState != stepTo && LogStep <= stepTo && DateTime.Now < Till)
                    {
                        StepState = ini.ReadInt("Test State", "StepEnded", 0);
                        StepEnded = Math.Min(Math.Abs(StepState), stepTo);
                        // pass steps which has been ended till this moment
                        while (LogStep < StepEnded)
                        {
                            LogOutput(ref MsgCurr, ini, LogStep);

                            EventConsumer.FireStepPassed();
                            EventConsumer.FireBeginStep(StepNames[++LogStep]);
                        }
                        // check if step is ended
                        if (StepEnded != LogStep)
                        {
                            System.Threading.Thread.Sleep(100);
                            // output current messages from this step
                            LogOutput(ref MsgCurr, ini, LogStep);
                            continue;
                        }
                        // output remaining messages from this step
                        LogOutput(ref MsgCurr, ini, LogStep);

                        // step passed
                        if (StepState > 0)
                        {
                            EventConsumer.FireStepPassed();
                        }
                        // step failed
                        if (StepState < 0)
                        {
                            string ErrorLine;
                            GetErrorDescription(out ErrorLine);
                            throw new VideoException(ErrorLine);
                        }
                        // begin next step
                        if (LogStep < stepTo)
                        {
                            EventConsumer.FireBeginStep(StepNames[++LogStep]);
                        }
                    }
                }
                else
                {
                    Result.AsyncWaitHandle.WaitOne(Timeout);
                }
                if (!Result.IsCompleted)
                {   // timeout, no exception in stack
                    throw new VideoException("Connection Timeout");
                }
                if (ex != null)
                {   // action ends with exception
                    if (!InStep && (EventConsumer != null))
                    {
                        EventConsumer.FireBeginStep("Verifying connection state");
                    }
                    throw ex;
                }
            }
            catch (Exception exp)
            {
                if (StepEnded > stepToSetState || (StepEnded == stepToSetState && StepState > 0))
                {
                    State = successState;
                }
                if (exp.Message == "Error HRESULT E_FAIL has been returned from a call to a COM component.")
                {
                    throw new Exception("Operation failed");
                }
                else
                {
                    throw exp;
                }
            }

            successAction();
            State = successState;
        }
Example #37
0
        public static ContainerHistoryData NewInstance(ContainerId containerId, Resource
                                                       allocatedResource, NodeId assignedNode, Priority priority, long startTime, long
                                                       finishTime, string diagnosticsInfo, int containerExitCode, ContainerState containerState
                                                       )
        {
            ContainerHistoryData containerHD = new ContainerHistoryData();

            containerHD.SetContainerId(containerId);
            containerHD.SetAllocatedResource(allocatedResource);
            containerHD.SetAssignedNode(assignedNode);
            containerHD.SetPriority(priority);
            containerHD.SetStartTime(startTime);
            containerHD.SetFinishTime(finishTime);
            containerHD.SetDiagnosticsInfo(diagnosticsInfo);
            containerHD.SetContainerExitStatus(containerExitCode);
            containerHD.SetContainerState(containerState);
            return(containerHD);
        }
Example #38
0
        public void Stop()
        {
            if (State != ContainerState.CS_Running)
            {
                return;
            }
            if ((TestControl == null) || (MediaControl == null))
            {
                throw new VideoException("Internal error in AV engine");
            }
            Exception ex         = null;
            Action    StopAction = new Action(() =>
            {
                try
                {
                    int StreamState     = 0;
                    State               = ContainerState.CS_Stopped;
                    VideoWindow.Visible = 0;
                    TestControl.GetStreamHealth(ref StreamState);
                    TestControl.ControlStream(2);
                    //if (StreamState > 0)// TODO why it works fine that way? why it locks instead sometimes?
                    {
                        System.Diagnostics.Trace.WriteLine("Trying to close DirectShow " + StreamState.ToString());
                        MediaControl.Stop();
                        System.Diagnostics.Trace.WriteLine("DirectShow closed");
                    }
                    //else
                    {
                        //System.Diagnostics.Trace.WriteLine("Bypassing DirectShow close as it is not safe " + StreamState.ToString());
                        //MediaControl.StopWhenReady();
                        //System.Diagnostics.Trace.WriteLine("DirectShow lazy close initiated");
                    }
                    TestControl.ControlStream(0);
                }
                catch (Exception e)
                {
                    ex = e;
                }
            });
            IAsyncResult StopResult = StopAction.BeginInvoke(null, null);

#if true
            ProceedAction(9, 10, StopResult, ref ex);
#else
            if (EventConsumer != null)
            {
                LogActivity(Timeout, 9, 10, StopResult);
            }
            else
            {
                StopResult.AsyncWaitHandle.WaitOne(Timeout);
            }
            if (!StopResult.IsCompleted)
            {
                throw new VideoException("Connection Timeout");
            }
            if (ex != null)
            {
                ProceedEx(ex);
                //throw ex;
            }
#endif
        }
Example #39
0
 public abstract void SetState(ContainerState state);
Example #40
0
        public static ContainerReport NewInstance(ContainerId containerId, Resource allocatedResource
                                                  , NodeId assignedNode, Priority priority, long creationTime, long finishTime, string
                                                  diagnosticInfo, string logUrl, int containerExitStatus, ContainerState containerState
                                                  , string nodeHttpAddress)
        {
            ContainerReport report = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <ContainerReport
                                                                                    >();

            report.SetContainerId(containerId);
            report.SetAllocatedResource(allocatedResource);
            report.SetAssignedNode(assignedNode);
            report.SetPriority(priority);
            report.SetCreationTime(creationTime);
            report.SetFinishTime(finishTime);
            report.SetDiagnosticsInfo(diagnosticInfo);
            report.SetLogUrl(logUrl);
            report.SetContainerExitStatus(containerExitStatus);
            report.SetContainerState(containerState);
            report.SetNodeHttpAddress(nodeHttpAddress);
            return(report);
        }
Example #41
0
        private async Task <List <string> > ListContainers(ContainerState containerState, ContainerFilter containerFilter, string param)
        {
            if (this.DockerClient == null)
            {
                return(null);
            }

            IDictionary <string, IDictionary <string, bool> > filter = new Dictionary <string, IDictionary <string, bool> >();

            if ((containerState & ContainerState.Exited) == ContainerState.Exited)
            {
                filter.Add("status", new Dictionary <string, bool>()
                {
                    { "exited", true }
                });
                filter.Add("name", new Dictionary <string, bool>()
                {
                    { param, true }
                });
            }

            if ((containerState & ContainerState.Created) == ContainerState.Created)
            {
                bool ok = filter.TryGetValue("status", out IDictionary <string, bool> f);
                if (ok)
                {
                    f.Add("created", true);
                }
                else
                {
                    filter.Add("status", new Dictionary <string, bool>()
                    {
                        { "created", true }
                    });
                    filter.Add("name", new Dictionary <string, bool>()
                    {
                        { param, true }
                    });
                }
            }
            else
            {
                if (containerFilter == ContainerFilter.Name)
                {
                    filter.Add("name", new Dictionary <string, bool>()
                    {
                        { param, true }
                    });
                }
                else if (containerFilter == ContainerFilter.Network)
                {
                    filter.Add("network", new Dictionary <string, bool>()
                    {
                        { param, true }
                    });
                }
            }

            Task <IList <ContainerListResponse> > responsesTask = this.DockerClient.Containers.ListContainersAsync
                                                                  (
                new ContainersListParameters()
            {
                Filters = filter
            }
                                                                  );

            responsesTask.Wait();
            IList <ContainerListResponse> responses = await responsesTask;

            List <string> containerIds = new List <string>();

            foreach (ContainerListResponse response in responses)
            {
                containerIds.Add(response.ID);
            }

            return(containerIds);
        }
Example #42
0
        public void Stop(bool kill)
        {
            lock (_ioLock)
            {
                ThrowIfDestroyed();

                if (constrainedProcessRunner != null)
                {
                    try
                    {
                        constrainedProcessRunner.StopAll(kill);
                    }
                    catch (TimeoutException)
                    {
                        jobObject.TerminateProcessesAndWait();
                    }
                    constrainedProcessRunner.Dispose();
                    constrainedProcessRunner = null;
                }

                if (processRunner != null)
                {
                    processRunner.StopAll(kill);
                    processRunner.Dispose();
                    processRunner = null;
                }

                this.currentState = ContainerState.Stopped;
            }
        }