| 1 | package WWW::VastAI::API::Endpoints; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 10 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Serverless endpoint management for Vast.ai | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 10 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 10 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 10 | ▶ | use WWW::VastAI::Endpoint; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 10 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 10 | has client => ( | |||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub _wrap { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | return WWW::VastAI::Endpoint->new( | |||||||||||||||||||||||||||||||||||||||||
| 19 | client => $self->client, | ||||||||||||||||||||||||||||||||||||||||||
| 20 | data => $data, | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub list { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list: called CC=5 SCAR=18.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my $result = $self->client->request_op('listEndpoints'); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | my $endpoints = ref $result eq 'HASH' ? ($result->{endpoints} || $result->{results} || []) : ($result || []); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition28%2/7
$result->{"endpoints"} or $result->{"results"} or []
$result->{"endpoints"} or $result->{"results"}
$result or []
MC/DC0%0/2
$result->{"endpoints"} or $result->{"results"} or []
$result->{"endpoints"}
$result->{"results"}
MC/DC0%0/1
$result or []
$result
Truth table33%1/3
A or B
A= $result->{"endpoints"}B= $result->{"results"}
Truth table0%0/2
A
A= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | return [ map { $self->_wrap($_) } @{$endpoints} ]; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | sub create { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my ($self, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | croak "endpoint_name required" unless $params{endpoint_name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | croak "min_load required" unless exists $params{min_load}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | croak "target_util required" unless exists $params{target_util}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $result = $self->client->request_op('createEndpoint', body => \%params); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | my $endpoint = ref $result eq 'HASH' ? ($result->{endpoint} || $result) : $result; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$result->{"endpoint"} or $result
MC/DC0%0/2
$result->{"endpoint"} or $result
$result->{"endpoint"}
$result
Truth table33%1/3
A or B
A= $result->{"endpoint"}B= $result
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | return $self->_wrap($endpoint); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | sub delete { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | ▶ | croak "endpoint id required" unless defined $id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | return $self->client->request_op('deleteEndpoint', path => { id => $id }); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | sub logs { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logs: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my ($self, $endpoint_name, %params) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | croak "endpoint_name required" unless $endpoint_name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | my %body = ( endpoint_name => $endpoint_name, %params ); | |||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | return $self->client->request_op('getEndpointLogs', body => \%body); | |||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | sub workers { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
workers: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my ($self, $endpoint_id) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | croak "endpoint id required" unless defined $endpoint_id; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return $self->client->request_op('getEndpointWorkers', body => { endpoint_id => $endpoint_id }); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||||||||||||||||