Skip to content

Node Information #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Jenkins.Net/Internal/Commands/NodesGetCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using JenkinsNET.Models;

namespace JenkinsNET.Internal.Commands
{
internal class NodesGetCommand : JenkinsHttpCommand
{
public IEnumerable<Models.JenkinsNode> Result { get; private set; }

public NodesGetCommand(IJenkinsContext context)
{
if (context == null)
throw new ArgumentNullException(nameof(context));

Url = NetPath.Combine(context.BaseUrl, "computer/", "api/xml");

UserName = context.UserName;
Password = context.Password;

OnWrite = request => {
request.Method = "GET";
};

OnRead = response => {
var document = ReadXml(response);
Result = document.Root.WrapGroup("computer", n => new JenkinsNode(n));
};

}

}
}
6 changes: 6 additions & 0 deletions Jenkins.Net/Jenkins.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net40|AnyCPU'">
<NoWarn>1591;1701;1702</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net40' or '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
6 changes: 6 additions & 0 deletions Jenkins.Net/JenkinsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public string Password {
/// </summary>
public JenkinsClientArtifacts Artifacts {get;}

/// <summary>
/// Group of methods for interacting with Jenkins Executors.
/// </summary>
public JenkinsClientNodes Nodes { get; }


/// <summary>
/// Creates a new Jenkins Client.
Expand All @@ -75,6 +80,7 @@ public JenkinsClient()
Builds = new JenkinsClientBuilds(this);
Queue = new JenkinsClientQueue(this);
Artifacts = new JenkinsClientArtifacts(this);
Nodes = new JenkinsClientNodes(this);
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions Jenkins.Net/JenkinsClientJobs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace JenkinsNET
public sealed class JenkinsClientJobs
{
private readonly IJenkinsContext context;



internal JenkinsClientJobs(IJenkinsContext context)
{
this.context = context;
Expand Down
36 changes: 36 additions & 0 deletions Jenkins.Net/JenkinsClientNodes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using JenkinsNET.Exceptions;
using JenkinsNET.Internal.Commands;
using JenkinsNET.Models;

namespace JenkinsNET
{
public class JenkinsClientNodes
{
private readonly IJenkinsContext context;


internal JenkinsClientNodes(IJenkinsContext context)
{
this.context = context;
}

/// <summary>
/// Gets the Jenkins Node information
/// </summary>
/// <exception cref="JenkinsNetException"></exception>
public IEnumerable<JenkinsNode> Get()
{
try {
var cmd = new NodesGetCommand(context);
cmd.Run();
return cmd.Result;
}
catch (Exception error) {
throw new JenkinsNetException("Failed to retrieve Jenkins description!", error);
}
}

}
}
62 changes: 62 additions & 0 deletions Jenkins.Net/Models/JenkinsNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Diagnostics;
using System.Xml.Linq;
using System.Xml.XPath;
using JenkinsNET.Internal;

namespace JenkinsNET.Models
{
public class JenkinsNode
{
/// <summary>
/// Gets the base XML node.
/// </summary>
public XElement Node { get; }

private string name;
private bool nameCached = false;
public string Name
{
get
{
if (nameCached) return name;
var node = Node.XPathSelectElement("./displayName");
name = node?.Value;
nameCached = true;
return name;
}
}

private string description;
private bool descriptionCached = false;
public string Description
{
get
{
if (descriptionCached) return description;
var node = Node.XPathSelectElement("./description");
description = node?.Value;
descriptionCached = true;
return description;
}
}

private bool online;
private bool onlineCached;
public bool Online
{
get
{
if (onlineCached) return online;
var node = Node.XPathSelectElement("./offline");
online = node?.Value == "false";
onlineCached = true;
return online;
}
}

internal JenkinsNode(XElement node)
{
this.Node = node;
}
}
}
2 changes: 1 addition & 1 deletion Jenkins.Net/Utilities/ProgressiveHtmlReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Update()
IsComplete = true;
}

#if !NET40
#if !NET40 && NET_ASYNC
/// <summary>
/// Retrieves and appends any additional text returned
/// by the running Jenkins Job asynchronously.
Expand Down
2 changes: 1 addition & 1 deletion Jenkins.Net/Utilities/ProgressiveTextReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void Update()
IsComplete = true;
}

#if !NET40
#if !NET40 && NET_ASYNC
/// <summary>
/// Retrieves and appends any additional text returned
/// by the running Jenkins Job asynchronously.
Expand Down