Skip to content

Commit

Permalink
ARGO-2280 Integrate WEBAPI as topology source in argo-ncg
Browse files Browse the repository at this point in the history
  • Loading branch information
eimamagi committed Jan 20, 2022
1 parent bf61c85 commit 00db2e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 53 deletions.
32 changes: 7 additions & 25 deletions src/modules/NCG/SiteInfo/WEBAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,13 @@ sub new
$self->{WEBAPI_ROOT_URL} = $DEFAULT_WEBAPI_ROOT_URL;
}

if (! exists $self->{NODE_MONITORED}) {
$self->{NODE_MONITORED} = '1';
}

if (! $self->{TOKEN}) {
$self->error("Authentication token must be defined.");
return;
}
if (! exists $self->{TIMEOUT}) {
$self->{TIMEOUT} = $self->{DEFAULT_HTTP_TIMEOUT};
}
if (! exists $self->{TYPE}) {
$self->{TYPE} = 'SITES';
}

if (! exists $self->{VO}) {
$self->{VO} = 'ops';
Expand All @@ -75,17 +68,13 @@ sub getData {
my $ua = LWP::UserAgent->new( timeout=>$self->{TIMEOUT}, env_proxy=>1 );
$ua->agent("NCG::SiteInfo::WEBAPI");
$url = $self->{WEBAPI_ROOT_URL} . $DEFAULT_WEBAPI_ROOT_URL_SUFFIX;
$url .= '?type=' . $self->{TYPE} . '&group=' . $sitename;
my @tags;
if ($self->{NODE_MONITORED}) {
push @tags, 'monitored:' . $self->{NODE_MONITORED};
}
if ($self->{SCOPE}) {
push @tags, 'scope:*'.$self->{SCOPE}.'*';
}
if (@tags) {
$url .= '&tags='.join(',',@tags);

if ($self->{FILTER}) {
$url .= '?' . $self->{FILTER} . '&group=' . $sitename;
} else {
$url .= '?group=' . $sitename;
}

my $req = HTTP::Request->new(GET => $url);
$req->header('x-api-key' => $self->{TOKEN});
$req->header('Accept' => 'application/json');
Expand Down Expand Up @@ -211,16 +200,9 @@ Module extracts list of sites from ARGO WEBAPI component.
Creates new NCG::SiteInfo::WEBAPI instance. Argument $options is hash
reference that can contain following elements:
NODE_MONITORED - filter only endpoints with tag monitored
FILTER - filter query that will be forwarded
(default: )
SCOPE - scope of sites
(default: )
TYPE - type of groups fetched from WEBAPI, EGI uses SITES,
most other tenants SERVICEGROUPS
(default: SITES)
TIMEOUT - HTTP timeout
(default: DEFAULT_HTTP_TIMEOUT inherited from NCG)
Expand Down
33 changes: 5 additions & 28 deletions src/modules/NCG/SiteSet/WEBAPI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ sub new
$self->{WEBAPI_ROOT_URL} = $DEFAULT_WEBAPI_ROOT_URL;
}

if (! exists $self->{TYPE}) {
$self->{TYPE} = 'NGI';
}

if (! $self->{TOKEN}) {
$self->error("Authentication token must be defined.");
return;
Expand All @@ -61,20 +57,11 @@ sub getData {
my $ua = LWP::UserAgent->new( timeout=>$self->{TIMEOUT}, env_proxy=>1 );
$ua->agent("NCG::SiteSet::WEBAPI");
$url = $self->{WEBAPI_ROOT_URL} . $DEFAULT_WEBAPI_ROOT_URL_SUFFIX;
$url .= '?type' . $self->{TYPE};
my @tags;
if ($self->{CERT_STATUS}) {
push @tags, 'certification:' . $self->{CERT_STATUS};
}
if ($self->{PROD_STATUS}) {
push @tags, 'infrastructure:' . $self->{PROD_STATUS};
}
if ($self->{SCOPE}) {
push @tags, 'scope:*'.$self->{SCOPE}.'*';
}
if (@tags) {
$url .= '&tags='.join(',',@tags);

if ($self->{FILTER}) {
$url .= '?' . $self->{FILTER} . '&group=' . $sitename;
}

my $req = HTTP::Request->new(GET => $url);
$req->header('x-api-key' => $self->{TOKEN});
$req->header('Accept' => 'application/json');
Expand Down Expand Up @@ -161,19 +148,9 @@ Module extracts list of sites from ARGO WEBAPI component.
Creates new NCG::SiteSet::WEBAPI instance. Argument $options is hash
reference that can contain following elements:
CERT_STATUS - certification status of site
(default: )
PROD_STATUS - production status of site
FILTER - filter query that will be forwarded
(default: )
SCOPE - scope of sites
(default: )
TYPE - type of groups fetched from WEBAPI, EGI uses NGI,
most other tenants PROJECT
(default: NGI)
TIMEOUT - HTTP timeout
(default: DEFAULT_HTTP_TIMEOUT inherited from NCG)
Expand Down

0 comments on commit 00db2e2

Please sign in to comment.