| 1 | package Google::Cloud::Run::V2::WorkerPoolsClient; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Moo; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use Google::gRPC::Client; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | use Google::Cloud::REST::Client; | ||
| 8 | use Google::Auth; | ||
| 9 | use Carp qw(croak); | ||
| 10 | |||
| 11 | use Protobuf; | ||
| 12 | use Google::Api::Common; | ||
| 13 | use Google::Cloud::Run::V2::Status; | ||
| 14 | use Google::Cloud::Run::V2::ContainerStatus; | ||
| 15 | use Google::Cloud::Run::V2::VendorSettings; | ||
| 16 | use Google::Cloud::Run::V2::K8sMin; | ||
| 17 | use Google::Cloud::Run::V2::InstanceSplit; | ||
| 18 | use Google::Cloud::Run::V2::TrafficTarget; | ||
| 19 | use Google::Cloud::Run::V2::Condition; | ||
| 20 | use Google::Cloud::Run::V2::Build; | ||
| 21 | use Google::Cloud::Run::V2::Sandbox; | ||
| 22 | use Google::Cloud::Run::V2::SourceUpload; | ||
| 23 | use Google::Cloud::Run::V2::Instance; | ||
| 24 | use Google::Cloud::Run::V2::RevisionTemplate; | ||
| 25 | use Google::Cloud::Run::V2::Task; | ||
| 26 | use Google::Cloud::Run::V2::WorkerPoolRevisionTemplate; | ||
| 27 | use Google::Cloud::Run::V2::TaskTemplate; | ||
| 28 | use Google::Cloud::Run::V2::Revision; | ||
| 29 | use Google::Cloud::Run::V2::Service; | ||
| 30 | use Google::Cloud::Run::V2::WorkerPool; | ||
| 31 | use Google::Cloud::Run::V2::Execution; | ||
| 32 | use Google::Cloud::Run::V2::ExecutionTemplate; | ||
| 33 | use Google::Cloud::Run::V2::Job; | ||
| 34 | |||
| 35 | our $VERSION = '0.06'; | ||
| 36 | |||
| 37 | has credentials => ( is => 'ro', required => 0 ); | ||
| 38 | has transport => ( is => 'rw' ); | ||
| 39 | |||
| 40 | sub BUILD { | ||
| 41 | my ($self) = @_; | ||
| 42 | |||
| 43 | my $auth = $self->credentials; | ||
| 44 | if (!defined $auth) { | ||
| 45 | $auth = Google::Auth->default(); | ||
| 46 | } elsif (!eval { $auth->can('get_token') }) { | ||
| 47 | croak 'Invalid credentials object: must implement get_token()'; | ||
| 48 | } | ||
| 49 | my $token = $auth->get_token(); | ||
| 50 | |||
| 51 | my $target = 'run.googleapis.com:443'; | ||
| 52 | my $t = $self->transport || 'grpc'; | ||
| 53 | |||
| 54 | if (ref($t) && eval { $t->can('call') }) { | ||
| 55 | # Already a transport object | ||
| 56 | } elsif (lc($t) eq 'rest') { | ||
| 57 | my $client = Google::Cloud::REST::Client->new( | ||
| 58 | target => $target, | ||
| 59 | auth_token => $token, | ||
| 60 | ); | ||
| 61 | $self->transport($client); | ||
| 62 | } else { | ||
| 63 | my $client = Google::gRPC::Client->new( | ||
| 64 | target => $target, | ||
| 65 | auth_token => $token, | ||
| 66 | ); | ||
| 67 | $self->transport($client); | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | sub create_worker_pool { | ||
| 72 | my ($self, %params) = @_; | ||
| 73 | |||
| 74 | my $request_class = 'Google::Cloud::Run::V2::WorkerPool::CreateWorkerPoolRequest'; | ||
| 75 | my $request = eval { $request_class->new(\%params) }; | ||
| 76 | my $new_err = $@; | ||
| 77 | if (!$request) { | ||
| 78 | $request = eval { $request_class->new(%params) }; | ||
| 79 | $new_err ||= $@; | ||
| 80 | } | ||
| 81 | if (!$request) { | ||
| 82 | croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error'); | ||
| 83 | } | ||
| 84 | |||
| 85 | my $response_class = 'Google::Longrunning::Operations::Operation'; | ||
| 86 | if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) { | ||
| 87 | return $self->transport->call({ | ||
| 88 | http_method => 'POST', | ||
| 89 | path => '/google.cloud.run.v2.WorkerPools/CreateWorkerPool', | ||
| 90 | request => $request, | ||
| 91 | response_class => $response_class, | ||
| 92 | }); | ||
| 93 | } | ||
| 94 | |||
| 95 | my $response = $self->transport->call({ | ||
| 96 | service => 'google.cloud.run.v2.WorkerPools', | ||
| 97 | method => 'CreateWorkerPool', | ||
| 98 | request => $request, | ||
| 99 | response_class => $response_class, | ||
| 100 | }); | ||
| 101 | |||
| 102 | return $response; | ||
| 103 | } | ||
| 104 | |||
| 105 | sub get_worker_pool { | ||
| 106 | my ($self, %params) = @_; | ||
| 107 | |||
| 108 | my $request_class = 'Google::Cloud::Run::V2::WorkerPool::GetWorkerPoolRequest'; | ||
| 109 | my $request = eval { $request_class->new(\%params) }; | ||
| 110 | my $new_err = $@; | ||
| 111 | if (!$request) { | ||
| 112 | $request = eval { $request_class->new(%params) }; | ||
| 113 | $new_err ||= $@; | ||
| 114 | } | ||
| 115 | if (!$request) { | ||
| 116 | croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error'); | ||
| 117 | } | ||
| 118 | |||
| 119 | my $response_class = 'Google::Cloud::Run::V2::WorkerPool::WorkerPool'; | ||
| 120 | if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) { | ||
| 121 | return $self->transport->call({ | ||
| 122 | http_method => 'POST', | ||
| 123 | path => '/google.cloud.run.v2.WorkerPools/GetWorkerPool', | ||
| 124 | request => $request, | ||
| 125 | response_class => $response_class, | ||
| 126 | }); | ||
| 127 | } | ||
| 128 | |||
| 129 | my $response = $self->transport->call({ | ||
| 130 | service => 'google.cloud.run.v2.WorkerPools', | ||
| 131 | method => 'GetWorkerPool', | ||
| 132 | request => $request, | ||
| 133 | response_class => $response_class, | ||
| 134 | }); | ||
| 135 | |||
| 136 | return $response; | ||
| 137 | } | ||
| 138 | |||
| 139 | sub update_worker_pool { | ||
| 140 | my ($self, %params) = @_; | ||
| 141 | |||
| 142 | my $request_class = 'Google::Cloud::Run::V2::WorkerPool::UpdateWorkerPoolRequest'; | ||
| 143 | my $request = eval { $request_class->new(\%params) }; | ||
| 144 | my $new_err = $@; | ||
| 145 | if (!$request) { | ||
| 146 | $request = eval { $request_class->new(%params) }; | ||
| 147 | $new_err ||= $@; | ||
| 148 | } | ||
| 149 | if (!$request) { | ||
| 150 | croak 'Failed to construct ' . $request_class . ': ' . ($new_err || 'unknown error'); | ||
| 151 | } | ||
| 152 | |||
| 153 | my $response_class = 'Google::Longrunning::Operations::Operation'; | ||
| 154 | if (eval { $self->transport->isa('Google::Cloud::REST::Client') }) { | ||
| 155 | return $self->transport->call({ | ||
| 156 | http_method => 'POST', | ||
| 157 | path => '/google.cloud.run.v2.WorkerPools/UpdateWorkerPool', | ||
| 158 | request => $request, | ||
| 159 | response_class => $response_class, | ||
| 160 | }); | ||
| 161 | } | ||
| 162 | |||
| 163 | my $response = $self->transport->call({ | ||
| 164 | service => 'google.cloud.run.v2.WorkerPools', | ||
| 165 | method => 'UpdateWorkerPool', | ||
| 166 | request => $request, | ||
| 167 | response_class => $response_class, | ||
| 168 | }); | ||
| 169 | |||
| 170 | return $response; | ||
| 171 | } | ||
| 172 | 1; # End of Google::Cloud::Run::V2::WorkerPoolsClient | ||
| 173 | |||
| 174 | __END__ | ||