Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

samples: migrate samples from java-docs-samples #73

Merged
merged 17 commits into from
Aug 31, 2020
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
1 change: 1 addition & 0 deletions .kokoro/nightly/integration.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ env_vars: {
key: "JOB_TYPE"
value: "integration"
}

# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
Expand Down
4 changes: 2 additions & 2 deletions .kokoro/presubmit/integration.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ env_vars: {

# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
key: "GOOGLE_CLOUD_PROJECT"
value: "gcloud-devel"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
key: "GCLOUD_PROJECT"
value: "gcloud-devel"
}

Expand Down
4 changes: 2 additions & 2 deletions .kokoro/presubmit/samples.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ env_vars: {

# TODO: remove this after we've migrated all tests and scripts
env_vars: {
key: "GCLOUD_PROJECT"
key: "GOOGLE_CLOUD_PROJECT"
value: "java-docs-samples-testing"
}

env_vars: {
key: "GOOGLE_CLOUD_PROJECT"
key: "GCLOUD_PROJECT"
value: "java-docs-samples-testing"
}

Expand Down
9 changes: 9 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,13 @@
</plugin>
</plugins>
</reporting>

<profiles>
<profile>
<id>enable-samples</id>
<modules>
<module>samples</module>
</modules>
</profile>
</profiles>
</project>
14 changes: 10 additions & 4 deletions samples/install-without-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>game-servers-install-without-bom</artifactId>
<artifactId>gameservices-install-without-bom</artifactId>
<packaging>jar</packaging>
<name>Google Cloud Gaming Install Without Bom</name>
<url>https://github.com/googleapis/java-game-servers</url>
<name>Google Cloud Game Services Install Without BOM Sample</name>
<url>https://github.com/googleapis/java-gameservices</url>

<!--
The parent pom defines common style checks and testing strategies for our samples.
Expand All @@ -23,7 +23,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<!-- {x-version-update-start:google-cloud-game-servers:released} -->
<dependencies>
<!-- [START game_servers_install_without_bom] -->
<dependency>
Expand All @@ -32,6 +32,11 @@
<version>0.21.0</version>
</dependency>
<!-- [END game_servers_install_without_bom] -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand All @@ -46,6 +51,7 @@
<scope>test</scope>
</dependency>
</dependencies>
<!-- {x-version-update-end} -->

<!-- compile and run all snippet tests -->
<build>
Expand Down
19 changes: 18 additions & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
</modules>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -53,4 +70,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
7 changes: 6 additions & 1 deletion samples/snapshot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
<version>0.21.1-SNAPSHOT</version>
</dependency>
<!-- {x-version-update-end} -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -80,4 +85,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
7 changes: 7 additions & 0 deletions samples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@

<dependencies>
<!-- TODO: use libraries-bom when google-cloud-game-servers is included -->
<!-- [START game_servers_install_with_bom] -->
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-game-servers</artifactId>
<version>0.21.0</version>
</dependency>
<!-- [END game_servers_install_with_bom] -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
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]
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]
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]
Loading