|
28 | 28 | if (count($argv) < 3 || count($argv) > 5) { |
29 | 29 | return printf("Usage: php %s PROJECT_ID INSTANCE_ID CLUSTER_ID [LOCATION_ID]" . PHP_EOL, __FILE__); |
30 | 30 | } |
31 | | -list($_, $project_id, $instance_id, $cluster_id) = $argv; |
32 | | -$location_id = isset($argv[4]) ? $argv[4] : 'us-east1-b'; |
| 31 | +list($_, $projectId, $instanceId, $clusterId) = $argv; |
| 32 | +$locationId = isset($argv[4]) ? $argv[4] : 'us-east1-b'; |
33 | 33 |
|
34 | 34 | // [START bigtable_create_dev_instance] |
35 | 35 |
|
|
41 | 41 | use Google\ApiCore\ApiException; |
42 | 42 |
|
43 | 43 | /** Uncomment and populate these variables in your code */ |
44 | | -// $project_id = 'The Google project ID'; |
45 | | -// $instance_id = 'The Bigtable instance ID'; |
46 | | -// $cluster_id = 'The Bigtable cluster ID'; |
47 | | -// $location_id = 'The Bigtable region ID'; |
| 44 | +// $projectId = 'The Google project ID'; |
| 45 | +// $instanceId = 'The Bigtable instance ID'; |
| 46 | +// $clusterId = 'The Bigtable cluster ID'; |
| 47 | +// $locationId = 'The Bigtable region ID'; |
48 | 48 |
|
49 | 49 |
|
50 | 50 | $instanceAdminClient = new BigtableInstanceAdminClient(); |
51 | 51 |
|
52 | | -$projectName = $instanceAdminClient->projectName($project_id); |
53 | | -$instanceName = $instanceAdminClient->instanceName($project_id, $instance_id); |
| 52 | +$projectName = $instanceAdminClient->projectName($projectId); |
| 53 | +$instanceName = $instanceAdminClient->instanceName($projectId, $instanceId); |
54 | 54 |
|
55 | 55 |
|
56 | 56 | printf("Creating a DEVELOPMENT Instance" . PHP_EOL); |
57 | 57 | // Set options to create an Instance |
58 | 58 |
|
59 | | -$storage_type = StorageType::HDD; |
| 59 | +$storageType = StorageType::HDD; |
60 | 60 | $development = InstanceType::DEVELOPMENT; |
61 | 61 | $labels = ['dev-label' => 'dev-label']; |
62 | 62 |
|
63 | 63 |
|
64 | 64 | # Create instance with given options |
65 | 65 | $instance = new Instance(); |
66 | | -$instance->setDisplayName($instance_id); |
| 66 | +$instance->setDisplayName($instanceId); |
67 | 67 | $instance->setLabels($labels); |
68 | 68 | $instance->setType($development); |
69 | 69 |
|
70 | 70 | // Create cluster with given options |
71 | 71 | $cluster = new Cluster(); |
72 | | -$cluster->setDefaultStorageType($storage_type); |
| 72 | +$cluster->setDefaultStorageType($storageType); |
73 | 73 | $cluster->setLocation( |
74 | 74 | $instanceAdminClient->locationName( |
75 | | - $project_id, |
76 | | - $location_id |
| 75 | + $projectId, |
| 76 | + $locationId |
77 | 77 | ) |
78 | 78 | ); |
79 | 79 | $clusters = [ |
80 | | - $cluster_id => $cluster |
| 80 | + $clusterId => $cluster |
81 | 81 | ]; |
82 | 82 | // Create development instance with given options |
83 | 83 | try { |
84 | 84 | $instanceAdminClient->getInstance($instanceName); |
85 | | - printf("Instance %s already exists." . PHP_EOL, $instance_id); |
| 85 | + printf("Instance %s already exists." . PHP_EOL, $instanceId); |
86 | 86 | } catch (ApiException $e) { |
87 | 87 | if ($e->getStatus() === 'NOT_FOUND') { |
88 | | - printf("Creating a development Instance: %s" . PHP_EOL, $instance_id); |
| 88 | + printf("Creating a development Instance: %s" . PHP_EOL, $instanceId); |
89 | 89 | $operationResponse = $instanceAdminClient->createInstance( |
90 | 90 | $projectName, |
91 | | - $instance_id, |
| 91 | + $instanceId, |
92 | 92 | $instance, |
93 | 93 | $clusters |
94 | 94 | ); |
95 | 95 | $operationResponse->pollUntilComplete(); |
96 | 96 | if (!$operationResponse->operationSucceeded()) { |
97 | 97 | print('Error: ' . $operationResponse->getError()->getMessage()); |
98 | 98 | } else { |
99 | | - printf("Instance %s created.", $instance_id); |
| 99 | + printf("Instance %s created.", $instanceId); |
100 | 100 | } |
101 | 101 | } else { |
102 | 102 | throw $e; |
|
0 commit comments