Пример #1
0
	    /// <summary>
		/// Polls this server for the latest cruise control server project statuses and queues.
		/// </summary>
		public void Poll()
		{
			try
			{
			    CruiseServerSnapshot cruiseServerSnapshot = cruiseServerManager.GetCruiseServerSnapshot();
                if ((lastCruiseServerSnapshot == null) 
                    || (cruiseServerSnapshot == null)
                    || lastCruiseServerSnapshot.IsQueueSetSnapshotChanged(cruiseServerSnapshot.QueueSetSnapshot))
                {
                    OnQueueChanged(new MonitorServerQueueChangedEventArgs(this));
                }
                lastCruiseServerSnapshot = cruiseServerSnapshot;

                // Find any changes
                DetectAnyChanges(cruiseServerSnapshot);
			}
			catch (Exception ex)
			{
				Trace.WriteLine("ServerMonitorPoll Exception: " + ex);
                lastCruiseServerSnapshot = null;
				connectException = ex;
                OnQueueChanged(new MonitorServerQueueChangedEventArgs(this));
            }

			OnPolled(new MonitorServerPolledEventArgs(this));
		}
		public CruiseServerSnapshot GetCruiseServerSnapshot()
		{
			if (cachedSnapshot == null)
			{
				cachedSnapshot = wrappedManager.GetCruiseServerSnapshot();
			}
			return cachedSnapshot;
		}
		public void ShouldReturnNullIfNamedProjectNotFound()
		{
			ProjectStatus[] projectStatuses = new ProjectStatus[1];
			projectStatuses[0] = new ProjectStatus("no names", IntegrationStatus.Failure, DateTime.Now);

			CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, null);

			Assert.IsNull(cruiseServerSnapshot.GetProjectStatus("this doesn't match"));
		}
		public void ShouldDelegateFirstSnapshotGet()
		{
			CruiseServerSnapshot snapshot = new CruiseServerSnapshot();
			wrappedManagerMock.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);

			Assert.AreSame(snapshot, cachingManager.GetCruiseServerSnapshot());

			wrappedManagerMock.Verify();
		}
        public void CorrectAssignmentOfConstructorArguments()
        {
            ProjectStatus[] projectStatuses = new ProjectStatus[0];
            QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();

            CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, queueSetSnapshot);

            Assert.AreSame(projectStatuses, cruiseServerSnapshot.ProjectStatuses);
            Assert.AreSame(queueSetSnapshot, cruiseServerSnapshot.QueueSetSnapshot);
        }
		public void RetrieveSnapshotFromManager()
		{
			CruiseServerSnapshot snapshot = new CruiseServerSnapshot();

            Expect.Call(serverClient.GetCruiseServerSnapshot()).Return(snapshot);
            mocks.ReplayAll();
			CruiseServerSnapshot actual = manager.GetCruiseServerSnapshot();
			
			Assert.AreSame(snapshot, actual);
		}
Пример #7
0
        /// <summary>
        /// Compares two snapshots to see if they are equal.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            CruiseServerSnapshot other = obj as CruiseServerSnapshot;

            if (other == null)
            {
                return(false);
            }
            return(object.Equals(this.projectStatuses, other.projectStatuses) && object.Equals(this.queueSetSnapshot, other.queueSetSnapshot));
        }
		public void RetrieveSnapshotFromManager()
		{
            var snapshot= new CruiseServerSnapshot();
            Expect.Call(cruiseManagerMock.GetCruiseServerSnapshot())
                .IgnoreArguments()
                .Return(snapshot);
            mocks.ReplayAll();

            CruiseServerSnapshot result = manager.GetCruiseServerSnapshot();
			Assert.AreEqual(snapshot, result);
		}
        public void WhenPollIsCalledRetrievesANewCopyOfTheCruiseServerSnapshot()
		{
            CruiseServerSnapshot snapshot = new CruiseServerSnapshot();
            mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);

			monitor.Poll();

			// deliberately called twice: should not go back to server on 2nd call
            Assert.AreSame(snapshot, monitor.CruiseServerSnapshot);
            Assert.AreSame(snapshot, monitor.CruiseServerSnapshot);
		}
		public void ShouldFindProjectStatusBasedOnProjectName()
		{
			ProjectStatus[] projectStatuses = new ProjectStatus[2];
			projectStatuses[0] = new ProjectStatus("test1", IntegrationStatus.Failure, DateTime.Now);
			projectStatuses[1] = new ProjectStatus("test2", IntegrationStatus.Success, DateTime.Now);

			CruiseServerSnapshot cruiseServerSnapshot = new CruiseServerSnapshot(projectStatuses, null);

			Assert.AreSame(projectStatuses[0], cruiseServerSnapshot.GetProjectStatus("test1"));
			Assert.AreSame(projectStatuses[1], cruiseServerSnapshot.GetProjectStatus("test2"));
		}
		public void ThePollEventIsFiredWhenPollIsInvoked()
		{
			Assert.AreEqual(0, pollCount);

            CruiseServerSnapshot snapshot = new CruiseServerSnapshot();
            mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);
			monitor.Poll();
			Assert.AreEqual(1, pollCount);

            mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);
			monitor.Poll();
			Assert.AreEqual(2, pollCount);
		}
		public void ShouldDelegateSnapshotGetAfterCacheCleared()
		{
			CruiseServerSnapshot snapshot1 = new CruiseServerSnapshot();
			wrappedManagerMock.ExpectAndReturn("GetCruiseServerSnapshot", snapshot1);
			CruiseServerSnapshot snapshot2 = new CruiseServerSnapshot();
			wrappedManagerMock.ExpectAndReturn("GetCruiseServerSnapshot", snapshot2);

			Assert.AreSame(snapshot1, cachingManager.GetCruiseServerSnapshot());
			Assert.AreSame(snapshot1, cachingManager.GetCruiseServerSnapshot());
			((ICache) cachingManager).InvalidateCache();
			Assert.AreSame(snapshot2, cachingManager.GetCruiseServerSnapshot());

			wrappedManagerMock.Verify();
		}	
Пример #13
0
        /// <summary>
        /// Gets the projects and integration queues snapshot from this server.
        /// </summary>
        public override CruiseServerSnapshot GetCruiseServerSnapshot()
        {
            try
            {
                string response;

                try
                {
                    // Retrieve the XML from the server - 1.3 or later
                    var url = GenerateUrl("XmlServerReport.aspx");

                    webFunctions.SetCredentials(client, new Uri(url), false);
                    response = client.DownloadString(url);
                }
                catch (Exception)
                {
                    // Retrieve the XML from the server - earlier than 1.3
                    var url = GenerateUrl("XmlStatusReport.aspx");
                    response = client.DownloadString(url);
                }
                if (string.IsNullOrEmpty(response))
                {
                    throw new CommunicationsException("No data retrieved");
                }

                // Load the XML and parse it
                var document = new XmlDocument();
                document.LoadXml(response);

                var snapshot = new CruiseServerSnapshot();
                if (document.DocumentElement.Name == "CruiseControl")
                {
                    snapshot.ProjectStatuses = ParseProjects(document.SelectNodes("/CruiseControl/Projects/Project")).ToArray();

                    // Add all the queues
                    ParseQueues(document, snapshot);
                }
                else
                {
                    snapshot.ProjectStatuses = ParseProjects(document.SelectNodes("/Projects/Project")).ToArray();
                }
                return(snapshot);
            }
            catch (Exception error)
            {
                throw new CommunicationsException("Unable to retrieve project status from the remote server", error);
            }
        }
 public void ToStringSerialisesAllValues()
 {
     QueueSnapshot queueSnapshot = new QueueSnapshot("queue1");
     queueSnapshot.Requests.Add(new QueuedRequestSnapshot("test project", ProjectActivity.Pending));
     QueueSetSnapshot queueSetSnapshot = new QueueSetSnapshot();
     queueSetSnapshot.Queues.Add(queueSnapshot);
     ProjectStatus projectStatus = new ProjectStatus("test project", IntegrationStatus.Success, DateTime.Now);
     CruiseServerSnapshot snapshot = new CruiseServerSnapshot(
         new ProjectStatus[] { projectStatus },
         queueSetSnapshot);
     SnapshotResponse response = new SnapshotResponse();
     response.ErrorMessages.Add(new ErrorMessage("Error 1"));
     response.ErrorMessages.Add(new ErrorMessage("Error 2"));
     response.RequestIdentifier = "request";
     response.Result = ResponseResult.Success;
     response.Timestamp = DateTime.Now;
     response.Snapshot = snapshot;
     string actual = response.ToString();
     string expected = string.Format(System.Globalization.CultureInfo.CurrentCulture,"<snapshotResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
         "timestamp=\"{2:yyyy-MM-ddTHH:mm:ss.FFFFFFFzzz}\" identifier=\"{0}\" result=\"{1}\">" +
         "<error>Error 1</error>" +
         "<error>Error 2</error>" +
         "<snapshot>" +
             "<projects>" +
                 "<projectStatus showForceBuildButton=\"true\" showStartStopButton=\"true\" serverName=\"{6}\" status=\"Running\" buildStatus=\"Success\" name=\"test project\" " +
                     "queuePriority=\"0\" lastBuildDate=\"{3:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\" nextBuildTime=\"{4:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" +
                     "<activity type=\"Sleeping\" />" +
                     "<parameters />" +
                 "</projectStatus>" + 
             "</projects>" +
             "<queueSet>" +
                 "<queue name=\"queue1\">" +
                     "<queueRequest projectName=\"test project\" time=\"{5:yyyy-MM-ddTHH:mm:ss.FFFFFFF}\">" +
                         "<activity type=\"Pending\" />" +
                     "</queueRequest>" + 
                 "</queue>" +
             "</queueSet>" + 
         "</snapshot>" + 
         "</snapshotResponse>",
         response.RequestIdentifier,
         response.Result,
         response.Timestamp,
         projectStatus.LastBuildDate,
         projectStatus.NextBuildTime,
         DateTime.MinValue,
         Environment.MachineName);
     Assert.AreEqual(expected, actual);
 }
	    private static void AssertProjectsSerializedCorrectly(CruiseServerSnapshot snapshot)
	    {
	        ProjectStatus projectStatus1 = snapshot.ProjectStatuses[0];
	        Assert.AreEqual("SvnTest", projectStatus1.Name);
	        Assert.AreEqual(ProjectActivity.Sleeping, projectStatus1.Activity);
	        Assert.AreEqual(IntegrationStatus.Exception, projectStatus1.BuildStatus);
	        Assert.AreEqual("8", projectStatus1.LastBuildLabel);
	        Assert.AreEqual("http://mrtickle/ccnet/", projectStatus1.WebURL);

	        ProjectStatus projectStatus2 = snapshot.ProjectStatuses[1];
	        Assert.AreEqual("projectName", projectStatus2.Name);
	        Assert.AreEqual(ProjectActivity.Sleeping, projectStatus2.Activity);
	        Assert.AreEqual(IntegrationStatus.Success, projectStatus2.BuildStatus);
	        Assert.AreEqual("13", projectStatus2.LastBuildLabel);
	        Assert.AreEqual("http://mrtickle/ccnet/", projectStatus2.WebURL);
	    }
        public void RefreshCallsClientAndFiresEvent()
        {
            var snapshot = new CruiseServerSnapshot();
            var client = mocks.StrictMock<CruiseServerClientBase>();
            using (var watcher = new PollingServerWatcher(client))
            {
                Expect.Call(client.GetCruiseServerSnapshot()).Return(snapshot);
                mocks.ReplayAll();

                var eventFired = false;
                watcher.Update += (o, e) =>
                {
                    eventFired = true;
                };
                watcher.Refresh();

                mocks.VerifyAll();
                Assert.IsTrue(eventFired);
            }
        }
        public void PollingCallsClientAndFiresEvent()
        {
            var monitor = new ManualResetEvent(false);
            var snapshot = new CruiseServerSnapshot();
            var client = mocks.StrictMock<CruiseServerClientBase>();
            using (var watcher = new PollingServerWatcher(client))
            {
                Expect.Call(client.GetCruiseServerSnapshot()).Return(snapshot);
                mocks.ReplayAll();

                var eventFired = false;
                watcher.Update += (o, e) =>
                {
                    eventFired = true;
                    monitor.Set();
                };
                monitor.WaitOne(new TimeSpan(0, 0, 10), false);

                mocks.VerifyAll();
                Assert.IsTrue(eventFired);
            }
        }
Пример #18
0
        /// <summary>
        /// Parse the queue information.
        /// </summary>
        /// <param name="document"></param>
        /// <param name="snapshot"></param>
        private void ParseQueues(XmlDocument document, CruiseServerSnapshot snapshot)
        {
            foreach (XmlElement queueSnapshotEl in document.SelectNodes("/CruiseControl/Queues/Queue"))
            {
                // Retrieve the queue details
                var queueSnapshot = new QueueSnapshot
                {
                    QueueName = RetrieveAttributeValue(queueSnapshotEl, "name", string.Empty)
                };
                snapshot.QueueSetSnapshot.Queues.Add(queueSnapshot);

                // Retrieve the requests
                foreach (XmlElement requestEl in queueSnapshotEl.SelectNodes("Request"))
                {
                    var request = new QueuedRequestSnapshot
                    {
                        Activity    = new ProjectActivity(RetrieveAttributeValue(requestEl, "activity", "Unknown")),
                        ProjectName = RetrieveAttributeValue(requestEl, "projectName", string.Empty)
                    };
                    queueSnapshot.Requests.Add(request);
                }
            }
        }
 private CruiseServerSnapshot CreateCruiseServerSnapshot2()
 {
     CruiseServerSnapshot snapshot = new CruiseServerSnapshot();
     snapshot.QueueSetSnapshot.Queues.Add(new QueueSnapshot("Test"));
     snapshot.QueueSetSnapshot.Queues[0].Requests.Add(new QueuedRequestSnapshot("Project", ProjectActivity.CheckingModifications));
     return snapshot;
 }
Пример #20
0
        /// <summary>
        /// Checks for any changes to the list of projects on the server.
        /// </summary>
        /// <param name="cruiseServerSnapshot"></param>
        private void DetectAnyChanges(CruiseServerSnapshot cruiseServerSnapshot)
        {
            if ((cruiseServerSnapshot != null) && (ServerSnapshotChanged != null))
            {
                // Match all the current projects and find any new projects
                var newProjects = new List<string>();
                var oldProjects = new List<string>(currentProjects);
                foreach (var project in cruiseServerSnapshot.ProjectStatuses)
                {
                    if (!oldProjects.Contains(project.Name))
                    {
                        newProjects.Add(project.Name);
                    }
                    else
                    {
                        oldProjects.Remove(project.Name);
                    }
                }

                if (areCurrentProjectsLoaded && 
                    ((newProjects.Count > 0) || (oldProjects.Count > 0)))
                {
                    // Fire the event
                    var args = new ServerSnapshotChangedEventArgs(cruiseServerManager.DisplayName,
                        cruiseServerManager.Configuration,
                        newProjects,
                        oldProjects);
                    ServerSnapshotChanged(this, args);
                }

                if ((newProjects.Count > 0) || (oldProjects.Count > 0))
                {
                    // Update the current list
                    foreach (var oldProject in oldProjects)
                    {
                        currentProjects.Remove(oldProject);
                    }
                    currentProjects.AddRange(newProjects);
                }
                areCurrentProjectsLoaded = true;
            }
        }
        /// <summary>
        /// Alternate method for retrieving current status for all projects without
        /// exception handling, for use within other ICruiseServerManager methods
        /// to provide user feedback
        /// </summary>
        /// <returns></returns>
        public CruiseServerSnapshot GetCruiseServerSnapshotEx()
        {
            List<ProjectStatus> projectStatues = AllJobs
                .Where(a => ProjectsAndCurrentStatus.ContainsKey(a.Name))
                .Select(a => Api.GetProjectStatus(a.Url, ProjectsAndCurrentStatus[a.Name]))
                .ToList();

            // Reset the ProjectsAndCurrentStatus dictionary
            ProjectsAndCurrentStatus = projectStatues.ToDictionary(a => a.Name);

            var snapshot = new CruiseServerSnapshot(projectStatues.ToArray(), new QueueSetSnapshot());
            return snapshot;
        }
		public void InvalidateCache()
		{
			cachedSnapshot = null;
		}
        public void ProjectStatusReturnsTheStatusForTheNominatedProject()
        {
            ProjectStatus[] result = new ProjectStatus[]
				{
					CreateProjectStatus("a name"),
					CreateProjectStatus(PROJECT_NAME),
				};

            CruiseServerSnapshot snapshot = new CruiseServerSnapshot(result, null);
            mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);

            monitor.Poll(); // Force the snapshot to be loaded
            ProjectStatus projectStatus = monitor.GetProjectStatus(PROJECT_NAME);

            Assert.AreSame(result[1], projectStatus);
        }
Пример #24
0
        public CruiseServerSnapshot GetCruiseServerSnapshot()
        {
            var projectList = GetBuildList(true);
            var currentlyExecutingBuilds = GetExecutingBuilds();

            var projectStatuses = new List<ProjectStatus>();
            foreach (var build in projectList)
            {
                var projectStatus = new ProjectStatus
                {
                    Name = build.Key,
                    BuildStatus = build.Value.buildStatus == BuildStatus.Success
                        ? IntegrationStatus.Success
                        : IntegrationStatus.Failure,
                    Category = build.Value.buildStatus.ToString(),
                    LastBuildLabel = build.Value.number,
                    WebURL = build.Value.webUrl,
                    LastBuildDate = DateTime.ParseExact(build.Value.startDate, "yyyyMMddTHHmmsszzz", CultureInfo.InvariantCulture)
                };

                projectStatuses.Add(projectStatus);

                if (currentlyExecutingBuilds.ContainsKey(build.Key))
                {
                    projectStatus.Activity = ProjectActivity.Building;
                    projectStatus.LastBuildLabel = currentlyExecutingBuilds[build.Key].number;
                    projectStatus.Messages = new Message[1];
                    projectStatus.Messages[0] = new Message("Percent Complete: " + currentlyExecutingBuilds[build.Key].percentageComplete);
                    projectStatus.WebURL = currentlyExecutingBuilds[build.Key].webUrl;
                }
            }

            var snapshot = new CruiseServerSnapshot
            {
                ProjectStatuses = projectStatuses.ToArray()
            };

            ManageSiren(projectStatuses);
            return snapshot;
        }
        //[ExpectedException(typeof(ApplicationException), )]
        public void ProjectStatusThrowsIfProjectNotFound()
        {
            ProjectStatus[] result = new ProjectStatus[]
                {
                    CreateProjectStatus("a name"),
                    CreateProjectStatus("another name"),
            };

            CruiseServerSnapshot snapshot = new CruiseServerSnapshot(result, null);
            mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);

            monitor.Poll();// Force the snapshot to be loaded 

            Assert.That(delegate { monitor.GetProjectStatus(PROJECT_NAME); }, 
                        Throws.TypeOf<ApplicationException>().With.Message.EqualTo(
                            "Project 'projectName' not found on server"));
        }
Пример #26
0
 public TestWatcher()
 {
     Snapshot = new CruiseServerSnapshot
     {
         ProjectStatuses = new ProjectStatus[] {
                 new ProjectStatus {
                     Name = "Project1",
                     BuildStatus = IntegrationStatus.Success
                 },
                 new ProjectStatus{
                     Name = "Project2",
                     BuildStatus = IntegrationStatus.Success
                 }
             },
         QueueSetSnapshot = new QueueSetSnapshot
         {
             Queues = {
                     new QueueSnapshot {
                         QueueName = "Queue1"
                     }
                 }
         }
     };
 }
        public CruiseServerSnapshotOnServer(CruiseServerSnapshot cruiseServerSnapshot, IServerSpecifier serverSpecifier)
		{
			this.serverSpecifier = serverSpecifier;
            this.cruiseServerSnapshot = cruiseServerSnapshot;
		}
Пример #28
0
		public void SetUpAsIfExceptionOccurredOnConnect( Exception exception )
		{
            lastCruiseServerSnapshot = null;
			ConnectException = exception;
		}
        public void ExposesTheCruiseServerSnapshotOfTheContainedServer()
		{
            CruiseServerSnapshot snapshot = new CruiseServerSnapshot();
            mockServerManager.ExpectAndReturn("GetCruiseServerSnapshot", snapshot);

			monitor.Poll();

            Assert.AreEqual(snapshot, monitor.CruiseServerSnapshot);
		}
 private void AssertQueueSetChanged(bool result, QueueSetSnapshot firstSnapshot, QueueSetSnapshot secondSnapshot)
 {
     CruiseServerSnapshot cruiseServerSnapshot1 = new CruiseServerSnapshot(null, firstSnapshot);
     CruiseServerSnapshot cruiseServerSnapshot2 = new CruiseServerSnapshot(null, secondSnapshot);
     Assert.AreEqual(result, cruiseServerSnapshot1.IsQueueSetSnapshotChanged(cruiseServerSnapshot2.QueueSetSnapshot));
 }