Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh gapics #679

Merged
merged 17 commits into from
Oct 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"monolog/monolog": "~1",
"psr/http-message": "1.0.*",
"ramsey/uuid": "~3",
"google/proto-client": "^0.23",
"google/gax": "^0.23"
"google/proto-client": "^0.24",
"google/gax": "^0.24"
},
"require-dev": {
"phpunit/phpunit": "4.8.*",
Expand Down Expand Up @@ -117,4 +117,4 @@
]
}
}
}
}
12 changes: 7 additions & 5 deletions src/Core/GrpcRequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ public function send(callable $request, array $args, array $options = [])
});

if (!isset($grpcOptions['retrySettings'])) {
$grpcOptions['retrySettings'] = new RetrySettings(null, null);
}

if ($timeout && !array_key_exists('timeoutMs', $grpcOptions)) {
$grpcOptions['timeoutMs'] = $timeout * 1000;
$retrySettings = [
'retriesEnabled' => false
];
if ($timeout) {
$retrySettings['noRetriesRpcTimeoutMillis'] = $timeout * 1000;
}
$grpcOptions['retrySettings'] = $retrySettings;
}

$optionalArgs = &$args[count($args) - 1];
Expand Down
281 changes: 171 additions & 110 deletions src/Dlp/V2beta1/Gapic/DlpServiceGapicClient.php

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Dlp/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"minimum-stability": "stable",
"require": {
"ext-grpc": "*",
"google/proto-client": "^0.23",
"google/gax": "^0.23"
"google/proto-client": "^0.24",
"google/gax": "^0.24"
},
"extra": {
"component": {
Expand Down
187 changes: 111 additions & 76 deletions src/ErrorReporting/V1beta1/Gapic/ErrorGroupServiceGapicClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,17 @@

namespace Google\Cloud\ErrorReporting\V1beta1\Gapic;

use Google\Cloud\Version;
use Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroup;
use Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroupServiceGrpcClient;
use Google\Devtools\Clouderrorreporting\V1beta1\GetGroupRequest;
use Google\Devtools\Clouderrorreporting\V1beta1\UpdateGroupRequest;
use Google\GAX\AgentHeaderDescriptor;
use Google\GAX\ApiCallable;
use Google\GAX\CallSettings;
use Google\GAX\GrpcConstants;
use Google\GAX\GrpcCredentialsHelper;
use Google\GAX\PathTemplate;
use Google\GAX\ValidationException;

/**
* Service Description: Service for retrieving and updating individual error groups.
Expand All @@ -54,7 +55,7 @@
* ```
* try {
* $errorGroupServiceClient = new ErrorGroupServiceClient();
* $formattedGroupName = ErrorGroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]");
* $formattedGroupName = $errorGroupServiceClient->groupName("[PROJECT]", "[GROUP]");
* $response = $errorGroupServiceClient->getGroup($formattedGroupName);
* } finally {
* $errorGroupServiceClient->close();
Expand All @@ -63,8 +64,8 @@
*
* Many parameters require resource names to be formatted in a particular way. To assist
* with these names, this class includes a format method for each type of name, and additionally
* a parse method to extract the individual identifiers contained within names that are
* returned.
* a parseName method to extract the individual identifiers contained within formatted names
* that are returned by the API.
*
* @experimental
*/
Expand All @@ -80,11 +81,6 @@ class ErrorGroupServiceGapicClient
*/
const DEFAULT_SERVICE_PORT = 443;

/**
* The default timeout for non-retrying methods.
*/
const DEFAULT_TIMEOUT_MILLIS = 30000;

/**
* The name of the code generator, to be included in the agent header.
*/
Expand All @@ -96,13 +92,50 @@ class ErrorGroupServiceGapicClient
const CODEGEN_VERSION = '0.0.5';

private static $groupNameTemplate;
private static $pathTemplateMap;
private static $gapicVersion;
private static $gapicVersionLoaded = false;

protected $grpcCredentialsHelper;
protected $errorGroupServiceStub;
private $scopes;
private $defaultCallSettings;
private $descriptors;

private static function getGroupNameTemplate()
{
if (self::$groupNameTemplate == null) {
self::$groupNameTemplate = new PathTemplate('projects/{project}/groups/{group}');
}

return self::$groupNameTemplate;
}

private static function getPathTemplateMap()
{
if (self::$pathTemplateMap == null) {
self::$pathTemplateMap = [
'group' => self::getGroupNameTemplate(),
];
}

return self::$pathTemplateMap;
}

private static function getGapicVersion()
{
if (!self::$gapicVersionLoaded) {
if (file_exists(__DIR__.'/../VERSION')) {
self::$gapicVersion = trim(file_get_contents(__DIR__.'/../VERSION'));
} elseif (class_exists(Version::class)) {
self::$gapicVersion = Version::VERSION;
}
self::$gapicVersionLoaded = true;
}

return self::$gapicVersion;
}

/**
* Formats a string containing the fully-qualified path to represent
* a group resource.
Expand All @@ -113,7 +146,7 @@ class ErrorGroupServiceGapicClient
* @return string The formatted group resource.
* @experimental
*/
public static function formatGroupName($project, $group)
public static function groupName($project, $group)
{
return self::getGroupNameTemplate()->render([
'project' => $project,
Expand All @@ -122,51 +155,44 @@ public static function formatGroupName($project, $group)
}

/**
* Parses the project from the given fully-qualified path which
* represents a group resource.
* Parses a formatted name string and returns an associative array of the components in the name.
* The following name formats are supported:
* Template: Pattern
* - group: projects/{project}/groups/{group}.
*
* @param string $groupName The fully-qualified group resource.
* The optional $template argument can be supplied to specify a particular pattern, and must
* match one of the templates listed above. If no $template argument is provided, or if the
* $template argument does not match one of the templates listed, then parseName will check
* each of the supported templates, and return the first match.
*
* @return string The extracted project value.
* @experimental
*/
public static function parseProjectFromGroupName($groupName)
{
return self::getGroupNameTemplate()->match($groupName)['project'];
}

/**
* Parses the group from the given fully-qualified path which
* represents a group resource.
* @param string $formattedName The formatted name string
* @param string $template Optional name of template to match
*
* @param string $groupName The fully-qualified group resource.
* @return array An associative array from name component IDs to component values.
*
* @return string The extracted group value.
* @throws ValidationException If $formattedName could not be matched.
* @experimental
*/
public static function parseGroupFromGroupName($groupName)
public static function parseName($formattedName, $template = null)
{
return self::getGroupNameTemplate()->match($groupName)['group'];
}
$templateMap = self::getPathTemplateMap();

private static function getGroupNameTemplate()
{
if (self::$groupNameTemplate == null) {
self::$groupNameTemplate = new PathTemplate('projects/{project}/groups/{group}');
}
if ($template) {
if (!isset($templateMap[$template])) {
throw new ValidationException("Template name $template does not exist");
}

return self::$groupNameTemplate;
}
return $templateMap[$template]->match($formattedName);
}

private static function getGapicVersion()
{
if (file_exists(__DIR__.'/../VERSION')) {
return trim(file_get_contents(__DIR__.'/../VERSION'));
} elseif (class_exists('\Google\Cloud\ServiceBuilder')) {
return \Google\Cloud\ServiceBuilder::VERSION;
} else {
return;
foreach ($templateMap as $templateName => $pathTemplate) {
try {
return $pathTemplate->match($formattedName);
} catch (ValidationException $ex) {
// Swallow the exception to continue trying other path templates
}
}
throw new ValidationException("Input did not match any known format. Input: $formattedName");
}

/**
Expand All @@ -193,15 +219,20 @@ private static function getGapicVersion()
* A CredentialsLoader object created using the Google\Auth library.
* @type array $scopes A string array of scopes to use when acquiring credentials.
* Defaults to the scopes for the Stackdriver Error Reporting API.
* @type string $clientConfigPath
* Path to a JSON file containing client method configuration, including retry settings.
* Specify this setting to specify the retry behavior of all methods on the client.
* By default this settings points to the default client config file, which is provided
* in the resources folder. The retry settings provided in this option can be overridden
* by settings in $retryingOverride
* @type array $retryingOverride
* An associative array of string => RetryOptions, where the keys
* are method names (e.g. 'createFoo'), that overrides default retrying
* settings. A value of null indicates that the method in question should
* not retry.
* @type int $timeoutMillis The timeout in milliseconds to use for calls
* that don't use retries. For calls that use retries,
* set the timeout in RetryOptions.
* Default: 30000 (30 seconds)
* An associative array in which the keys are method names (e.g. 'createFoo'), and
* the values are retry settings to use for that method. The retry settings for each
* method can be a {@see Google\GAX\RetrySettings} object, or an associative array
* of retry settings parameters. See the documentation on {@see Google\GAX\RetrySettings}
* for example usage. Passing a value of null is equivalent to a value of
* ['retriesEnabled' => false]. Retry settings provided in this setting override the
* settings in $clientConfigPath.
* }
* @experimental
*/
Expand All @@ -214,9 +245,9 @@ public function __construct($options = [])
'https://www.googleapis.com/auth/cloud-platform',
],
'retryingOverride' => null,
'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS,
'libName' => null,
'libVersion' => null,
'clientConfigPath' => __DIR__.'/../resources/error_group_service_client_config.json',
];
$options = array_merge($defaultOptions, $options);

Expand All @@ -234,15 +265,13 @@ public function __construct($options = [])
'updateGroup' => $defaultDescriptors,
];

$clientConfigJsonString = file_get_contents(__DIR__.'/../resources/error_group_service_client_config.json');
$clientConfigJsonString = file_get_contents($options['clientConfigPath']);
$clientConfig = json_decode($clientConfigJsonString, true);
$this->defaultCallSettings =
CallSettings::load(
'google.devtools.clouderrorreporting.v1beta1.ErrorGroupService',
$clientConfig,
$options['retryingOverride'],
GrpcConstants::getStatusCodeNames(),
$options['timeoutMillis']
$options['retryingOverride']
);

$this->scopes = $options['scopes'];
Expand All @@ -269,7 +298,7 @@ public function __construct($options = [])
* ```
* try {
* $errorGroupServiceClient = new ErrorGroupServiceClient();
* $formattedGroupName = ErrorGroupServiceClient::formatGroupName("[PROJECT]", "[GROUP]");
* $formattedGroupName = $errorGroupServiceClient->groupName("[PROJECT]", "[GROUP]");
* $response = $errorGroupServiceClient->getGroup($formattedGroupName);
* } finally {
* $errorGroupServiceClient->close();
Expand All @@ -287,12 +316,11 @@ public function __construct($options = [])
* @param array $optionalArgs {
* Optional.
*
* @type \Google\GAX\RetrySettings $retrySettings
* Retry settings to use for this call. If present, then
* $timeoutMillis is ignored.
* @type int $timeoutMillis
* Timeout to use for this call. Only used if $retrySettings
* is not set.
* @type \Google\GAX\RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\GAX\RetrySettings} object, or an associative array
* of retry settings parameters. See the documentation on
* {@see Google\GAX\RetrySettings} for example usage.
* }
*
* @return \Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroup
Expand All @@ -305,9 +333,13 @@ public function getGroup($groupName, $optionalArgs = [])
$request = new GetGroupRequest();
$request->setGroupName($groupName);

$mergedSettings = $this->defaultCallSettings['getGroup']->merge(
new CallSettings($optionalArgs)
);
$defaultCallSettings = $this->defaultCallSettings['getGroup'];
if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) {
$optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with(
$optionalArgs['retrySettings']
);
}
$mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs));
$callable = ApiCallable::createApiCall(
$this->errorGroupServiceStub,
'GetGroup',
Expand Down Expand Up @@ -340,12 +372,11 @@ public function getGroup($groupName, $optionalArgs = [])
* @param array $optionalArgs {
* Optional.
*
* @type \Google\GAX\RetrySettings $retrySettings
* Retry settings to use for this call. If present, then
* $timeoutMillis is ignored.
* @type int $timeoutMillis
* Timeout to use for this call. Only used if $retrySettings
* is not set.
* @type \Google\GAX\RetrySettings|array $retrySettings
* Retry settings to use for this call. Can be a
* {@see Google\GAX\RetrySettings} object, or an associative array
* of retry settings parameters. See the documentation on
* {@see Google\GAX\RetrySettings} for example usage.
* }
*
* @return \Google\Devtools\Clouderrorreporting\V1beta1\ErrorGroup
Expand All @@ -358,9 +389,13 @@ public function updateGroup($group, $optionalArgs = [])
$request = new UpdateGroupRequest();
$request->setGroup($group);

$mergedSettings = $this->defaultCallSettings['updateGroup']->merge(
new CallSettings($optionalArgs)
);
$defaultCallSettings = $this->defaultCallSettings['updateGroup'];
if (isset($optionalArgs['retrySettings']) && is_array($optionalArgs['retrySettings'])) {
$optionalArgs['retrySettings'] = $defaultCallSettings->getRetrySettings()->with(
$optionalArgs['retrySettings']
);
}
$mergedSettings = $defaultCallSettings->merge(new CallSettings($optionalArgs));
$callable = ApiCallable::createApiCall(
$this->errorGroupServiceStub,
'UpdateGroup',
Expand Down
Loading