This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
samples: migrate samples from java-docs-samples (#73)
* samples: migrate samples from java-docs-samples * use java-docs-samples-testing project * ci: switch to GOOGLE_CLOUD_PROJECT env variable * samples: fix GkeClusterReference * chore: fix lint * test(samples): set default GKE cluster * samples: add install-without-bom and snapshot tests * deps: fix test deps * Update classpaths to v1. * Refactor samples path to com.examples.gameservices... * Fix lint failures. * Further rename package and add gson dependency. * Add GSON to install-without-bom. * Feedback update - propagate exceptions instead of catching and printing. * Propagate exceptions creating clients in GameServicesTestUtil. * Removing updates to kokoro config. Co-authored-by: Dane Zeke Liergaard <[email protected]>
- Loading branch information
1 parent
06f50ce
commit f775977
Showing
27 changed files
with
1,366 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
samples/snippets/src/main/java/com/example/gameservices/clusters/CreateCluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.gameservices.clusters; | ||
|
||
// [START cloud_game_servers_cluster_create] | ||
|
||
import com.google.api.gax.longrunning.OperationFuture; | ||
import com.google.cloud.gaming.v1.CreateGameServerClusterRequest; | ||
import com.google.cloud.gaming.v1.GameServerCluster; | ||
import com.google.cloud.gaming.v1.GameServerClusterConnectionInfo; | ||
import com.google.cloud.gaming.v1.GameServerClustersServiceClient; | ||
import com.google.cloud.gaming.v1.GkeClusterReference; | ||
import com.google.cloud.gaming.v1.OperationMetadata; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class CreateCluster { | ||
|
||
public static void createGameServerCluster( | ||
String projectId, String regionId, String realmId, String clusterId, String gkeName) | ||
throws InterruptedException, ExecutionException, TimeoutException, IOException { | ||
// String projectId = "your-project-id"; | ||
// String regionId = "us-central1-f"; | ||
// String realmId = "your-realm-id"; | ||
// String clusterId = "your-game-server-cluster-id"; | ||
// String gkeName = "projects/your-project-id/locations/us-central1/clusters/test"; | ||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (GameServerClustersServiceClient client = GameServerClustersServiceClient.create()) { | ||
String parent = | ||
String.format("projects/%s/locations/%s/realms/%s", projectId, regionId, realmId); | ||
String clusterName = String.format("%s/gameServerClusters/%s", parent, clusterId); | ||
|
||
GameServerCluster gameServerCluster = | ||
GameServerCluster.newBuilder() | ||
.setName(clusterName) | ||
.setConnectionInfo( | ||
GameServerClusterConnectionInfo.newBuilder() | ||
.setGkeClusterReference( | ||
GkeClusterReference.newBuilder().setCluster(gkeName).build()) | ||
.setNamespace("default")) | ||
.build(); | ||
|
||
CreateGameServerClusterRequest request = | ||
CreateGameServerClusterRequest.newBuilder() | ||
.setParent(parent) | ||
.setGameServerClusterId(clusterId) | ||
.setGameServerCluster(gameServerCluster) | ||
.build(); | ||
|
||
OperationFuture<GameServerCluster, OperationMetadata> call = | ||
client.createGameServerClusterAsync(request); | ||
|
||
GameServerCluster created = call.get(1, TimeUnit.MINUTES); | ||
System.out.println("Game Server Cluster created: " + created.getName()); | ||
} | ||
} | ||
} | ||
// [END cloud_game_servers_cluster_create] |
54 changes: 54 additions & 0 deletions
54
samples/snippets/src/main/java/com/example/gameservices/clusters/DeleteCluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.gameservices.clusters; | ||
|
||
// [START cloud_game_servers_cluster_delete] | ||
|
||
import com.google.api.gax.longrunning.OperationFuture; | ||
import com.google.cloud.gaming.v1.GameServerClustersServiceClient; | ||
import com.google.cloud.gaming.v1.OperationMetadata; | ||
import com.google.protobuf.Empty; | ||
import java.io.IOException; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
|
||
public class DeleteCluster { | ||
|
||
public static void deleteGameServerCluster( | ||
String projectId, String regionId, String realmId, String clusterId) | ||
throws IOException, InterruptedException, ExecutionException, TimeoutException { | ||
// String projectId = "your-project-id"; | ||
// String regionId = "us-central1-f"; | ||
// String clusterId = "your-game-server-cluster-id"; | ||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (GameServerClustersServiceClient client = GameServerClustersServiceClient.create()) { | ||
String parent = | ||
String.format("projects/%s/locations/%s/realms/%s", projectId, regionId, realmId); | ||
String clusterName = String.format("%s/gameServerClusters/%s", parent, clusterId); | ||
|
||
OperationFuture<Empty, OperationMetadata> call = | ||
client.deleteGameServerClusterAsync(clusterName); | ||
|
||
call.get(1, TimeUnit.MINUTES); | ||
System.out.println("Game Server Cluster deleted: " + clusterName); | ||
} | ||
} | ||
} | ||
// [END cloud_game_servers_cluster_delete] |
47 changes: 47 additions & 0 deletions
47
samples/snippets/src/main/java/com/example/gameservices/clusters/GetCluster.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2019 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.gameservices.clusters; | ||
|
||
// [START cloud_game_servers_cluster_get] | ||
|
||
import com.google.cloud.gaming.v1.GameServerCluster; | ||
import com.google.cloud.gaming.v1.GameServerClustersServiceClient; | ||
import java.io.IOException; | ||
|
||
public class GetCluster { | ||
|
||
public static void getGameServerCluster( | ||
String projectId, String regionId, String realmId, String clusterId) throws IOException { | ||
// String projectId = "your-project-id"; | ||
// String regionId = "us-central1-f"; | ||
// String realmId = "your-realm-id"; | ||
// String clusterId = "your-game-server-cluster-id"; | ||
// Initialize client that will be used to send requests. This client only needs to be created | ||
// once, and can be reused for multiple requests. After completing all of your requests, call | ||
// the "close" method on the client to safely clean up any remaining background resources. | ||
try (GameServerClustersServiceClient client = GameServerClustersServiceClient.create()) { | ||
String parent = | ||
String.format("projects/%s/locations/%s/realms/%s", projectId, regionId, realmId); | ||
String clusterName = String.format("%s/gameServerClusters/%s", parent, clusterId); | ||
|
||
GameServerCluster cluster = client.getGameServerCluster(clusterName); | ||
|
||
System.out.println("Game Server Cluster found: " + cluster.getName()); | ||
} | ||
} | ||
} | ||
// [END cloud_game_servers_cluster_get] |
Oops, something went wrong.