Skip to content

Commit

Permalink
fix: Use httpd-port configuration for Deploy task remote peers port
Browse files Browse the repository at this point in the history
Use remote-workers config to sefine peers scanner number
  • Loading branch information
g-bougard committed Jul 3, 2024
1 parent f3cb4d3 commit b295ca0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ netdiscovery/netinventory:
* Fixed tasks blocking on windows with core concurrent calls control
* Avoid to expire SSL CA certs cache in threads

deploy:
* For job with P2P enabled, don't use hard-coded 62354 port, but agent httpd-port
configuration to discover listening peer agents.
* For job with P2P enabled, use remote-workers configuration to optimize peers
discovery keeping 10 workers as minimum default.

esx:
* fix #691: Fix perl error while checking esx configuration template

Expand Down
18 changes: 13 additions & 5 deletions lib/GLPI/Agent/Task/Deploy/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ sub download {
die;
}

# Use port from configuration, it is available from datastore object
my $port = $self->{datastore}->{config}->{'httpd-port'} || 62354;

# Use remote-workers from configuration as max_worker, but keep 10 as minimum default
my $workers = $self->{datastore}->{config}->{'remote-workers'} || 10;
$workers = 10 unless $workers >= 10;

my @peers;
if ($self->{p2p}) {
GLPI::Agent::Task::Deploy::P2P->require();
Expand All @@ -165,10 +172,11 @@ sub download {
my $p2p = GLPI::Agent::Task::Deploy::P2P->new(
scan_timeout => 1,
datastore => $self->{datastore},
max_worker => $workers,
logger => $self->{logger}
);
eval {
@peers = $p2p->findPeers(62354);
@peers = $p2p->findPeers($port);
$self->{p2pnet} = $p2p;
};
$self->{logger}->debug("failed to enable P2P: $EVAL_ERROR")
Expand All @@ -187,13 +195,13 @@ sub download {

# try to download from the same peer as last part, if defined
if ($lastPeer) {
my $success = $self->_downloadPeer($lastPeer, $sha512, $path);
my $success = $self->_downloadPeer($lastPeer, $sha512, $path, $port);
next PART if $success;
}

# try to download from peers
foreach my $peer (@peers) {
my $success = $self->_downloadPeer($peer, $sha512, $path);
my $success = $self->_downloadPeer($peer, $sha512, $path, $port);
if ($success) {
$lastPeer = $peer;
next PART;
Expand Down Expand Up @@ -233,9 +241,9 @@ sub _getNextPathUpdateTime {
}

sub _downloadPeer {
my ($self, $peer, $sha512, $path) = @_;
my ($self, $peer, $sha512, $path, $port) = @_;

my $source = 'http://'.$peer.':62354/deploy/getFile/';
my $source = 'http://'.$peer.':'.$port.'/deploy/getFile/';

return $self->_download($source, $sha512, $path, $peer);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/GLPI/Agent/Task/Deploy/P2P.pm
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ sub _scanPeers {
$manager->run_on_finish(sub {
my ($pid, $exit_code, $address) = @_;
push @found, $address if $exit_code;
});
});

foreach my $address (@addresses) {
$manager->start($address) and next;
Expand Down

0 comments on commit b295ca0

Please sign in to comment.