Skip to content

Commit

Permalink
merge missing commits
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm360 committed Oct 8, 2024
2 parents 8acabee + b2d3278 commit cb77cd2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/BeehiveManager.Services/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public static class LoggerExtensions
new EventId(0, nameof(NodeCashedOut)),
"Node {BeeNodeId} cashed out {BzzCashedOut} BZZ with tx hashes {TxHashes}");

private static readonly Action<ILogger, string, bool, Exception> _nodeConfigurationUpdated =
LoggerMessage.Define<string, bool>(
private static readonly Action<ILogger, string, Exception> _nodeConfigurationUpdated =
LoggerMessage.Define<string>(
LogLevel.Information,
new EventId(7, nameof(NodeConfigurationUpdated)),
"Node {BeeNodeId} updated configuration. EnableBatchCreation: {EnableBatchCreation}");
"Node {BeeNodeId} updated configuration");

private static readonly Action<ILogger, string, Uri, int, bool, Exception> _nodeRegistered =
LoggerMessage.Define<string, Uri, int, bool>(
Expand Down Expand Up @@ -120,8 +120,8 @@ public static void FailedToWithdrawBzzOnNodeChequeBook(this ILogger logger, stri
public static void NodeCashedOut(this ILogger logger, string beeNodeId, BzzBalance bzzCashedOut, IEnumerable<string> txHashes) =>
_nodeCashedOut(logger, beeNodeId, bzzCashedOut, txHashes, null!);

public static void NodeConfigurationUpdated(this ILogger logger, string beeNodeid, bool enableBatchCreation) =>
_nodeConfigurationUpdated(logger, beeNodeid, enableBatchCreation, null!);
public static void NodeConfigurationUpdated(this ILogger logger, string beeNodeid) =>
_nodeConfigurationUpdated(logger, beeNodeid, null!);

public static void NodeRegistered(this ILogger logger, string beeNodeId, Uri nodeUrl, int gatewayPort, bool isBatchCreationEnabled) =>
_nodeRegistered(logger, beeNodeId, nodeUrl, gatewayPort, isBatchCreationEnabled, null!);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@
// You should have received a copy of the GNU Affero General Public License along with BeehiveManager.
// If not, see <https://www.gnu.org/licenses/>.

using System.ComponentModel.DataAnnotations;

namespace Etherna.BeehiveManager.Areas.Api.InputModels
{
public class UpdateNodeConfigInput
{
public bool EnableBatchCreation { get; set; }
[Range(1, 65535)]
public int? ApiPort { get; set; }

public string? ConnectionScheme { get; set; }

public bool? EnableBatchCreation { get; set; }

public string? Hostname { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public interface INodesControllerService
Task NotifyPinningOfUploadedContentAsync(string id, SwarmHash hash);
Task RemoveBeeNodeAsync(string id);
Task ReuploadResourceToNetworkFromNodeAsync(string id, SwarmHash hash);
Task UpdateNodeConfigAsync(string id, UpdateNodeConfigInput config);
Task UpdateNodeConfigAsync(string id, UpdateNodeConfigInput newConfig);
}
}
44 changes: 37 additions & 7 deletions src/BeehiveManager/Areas/Api/Services/NodesControllerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,51 @@ public async Task ReuploadResourceToNetworkFromNodeAsync(string id, SwarmHash ha
await beeNodeInstance.Client.ReuploadContentAsync(hash);
}

public async Task UpdateNodeConfigAsync(string id, UpdateNodeConfigInput config)
public async Task UpdateNodeConfigAsync(string id, UpdateNodeConfigInput newConfig)
{
ArgumentNullException.ThrowIfNull(id, nameof(id));
ArgumentNullException.ThrowIfNull(config, nameof(config));
ArgumentNullException.ThrowIfNull(newConfig, nameof(newConfig));

// Update live instance.
// Update live instance and db config.
bool rebuildLiveInstance = false;
var nodeLiveInstance = await beeNodeLiveManager.GetBeeNodeLiveInstanceAsync(id);
nodeLiveInstance.IsBatchCreationEnabled = config.EnableBatchCreation;
var nodeDb = await beehiveDbContext.BeeNodes.FindOneAsync(id);

if (newConfig.ConnectionScheme != null)
{
rebuildLiveInstance = true;
nodeDb.ConnectionScheme = newConfig.ConnectionScheme;
}

if (newConfig.EnableBatchCreation != null)
{
nodeLiveInstance.IsBatchCreationEnabled = newConfig.EnableBatchCreation.Value;
nodeDb.IsBatchCreationEnabled = newConfig.EnableBatchCreation.Value;
}

if (newConfig.ApiPort != null)
{
rebuildLiveInstance = true;
nodeDb.GatewayPort = newConfig.ApiPort.Value;
}

if (newConfig.Hostname != null)
{
rebuildLiveInstance = true;
nodeDb.Hostname = newConfig.Hostname;
}

// Update config on db.
var node = await beehiveDbContext.BeeNodes.FindOneAsync(id);
node.IsBatchCreationEnabled = config.EnableBatchCreation;
await beehiveDbContext.SaveChangesAsync();

// Rebuild live instance if necessary (changed connection string)
if (rebuildLiveInstance)
{
beeNodeLiveManager.RemoveBeeNode(id);
await beeNodeLiveManager.AddBeeNodeAsync(nodeDb);
}

logger.NodeConfigurationUpdated(id, config.EnableBatchCreation);
logger.NodeConfigurationUpdated(id);
}
}
}

0 comments on commit cb77cd2

Please sign in to comment.