use of com.google.cloud.tasks.v2.LocationName in project java-cloudbuild by googleapis.
the class CloudBuildClientTest method createWorkerPoolTest.
@Test
public void createWorkerPoolTest() throws Exception {
WorkerPool expectedResponse = WorkerPool.newBuilder().setName(WorkerPoolName.of("[PROJECT]", "[LOCATION]", "[WORKER_POOL]").toString()).setDisplayName("displayName1714148973").setUid("uid115792").putAllAnnotations(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).setDeleteTime(Timestamp.newBuilder().build()).setEtag("etag3123477").build();
Operation resultOperation = Operation.newBuilder().setName("createWorkerPoolTest").setDone(true).setResponse(Any.pack(expectedResponse)).build();
mockCloudBuild.addResponse(resultOperation);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
WorkerPool workerPool = WorkerPool.newBuilder().build();
String workerPoolId = "workerPoolId-46320779";
WorkerPool actualResponse = client.createWorkerPoolAsync(parent, workerPool, workerPoolId).get();
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockCloudBuild.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateWorkerPoolRequest actualRequest = ((CreateWorkerPoolRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(workerPool, actualRequest.getWorkerPool());
Assert.assertEquals(workerPoolId, actualRequest.getWorkerPoolId());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.tasks.v2.LocationName in project google-cloud-java by GoogleCloudPlatform.
the class TranslateSnippetsBeta method createGlossary.
// [END translate_batch_translate_text_beta]
/**
* Creates a glossary.
*
* @param projectId - Id of the project.
* @param location - location name.
* @param name - Glossary name.
* @param gcsUri - Google Cloud Storage URI where glossary is stored in csv format.
*/
// [START translate_create_glossary_beta]
static Glossary createGlossary(String projectId, String location, String name, String gcsUri) {
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
LanguageCodesSet languageCodesSet = LanguageCodesSet.newBuilder().addLanguageCodes("en").addLanguageCodes("es").build();
GcsSource gcsSource = GcsSource.newBuilder().setInputUri(gcsUri).build();
GlossaryInputConfig glossaryInputConfig = GlossaryInputConfig.newBuilder().setGcsSource(gcsSource).build();
GlossaryName glossaryName = GlossaryName.newBuilder().setProject(projectId).setLocation(location).setGlossary(name).build();
Glossary glossary = Glossary.newBuilder().setLanguageCodesSet(languageCodesSet).setInputConfig(glossaryInputConfig).setName(glossaryName.toString()).build();
CreateGlossaryRequest request = CreateGlossaryRequest.newBuilder().setParent(locationName.toString()).setGlossary(glossary).build();
// Call the API
Glossary response = translationServiceClient.createGlossaryAsync(request).get(300, TimeUnit.SECONDS);
System.out.format("Created: %s\n", response.getName());
System.out.format("Input Uri: %s\n", response.getInputConfig().getGcsSource());
return response;
} catch (Exception e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.tasks.v2.LocationName in project google-cloud-java by GoogleCloudPlatform.
the class TranslateSnippetsBeta method translateText.
// [END translate_detect_language_beta]
// [START translate_translate_text_beta]
/**
* Translates a given text to a target language.
*
* @param projectId - Id of the project.
* @param location - location name.
* @param text - Text for translation.
* @param sourceLanguageCode - Language code of text. e.g. "en"
* @param targetLanguageCode - Language code for translation. e.g. "sr"
*/
static TranslateTextResponse translateText(String projectId, String location, String text, String sourceLanguageCode, String targetLanguageCode) {
try (TranslationServiceClient translationServiceClient = TranslationServiceClient.create()) {
LocationName locationName = LocationName.newBuilder().setProject(projectId).setLocation(location).build();
TranslateTextRequest translateTextRequest = TranslateTextRequest.newBuilder().setParent(locationName.toString()).setMimeType("text/plain").setSourceLanguageCode(sourceLanguageCode).setTargetLanguageCode(targetLanguageCode).addContents(text).build();
// Call the API
TranslateTextResponse response = translationServiceClient.translateText(translateTextRequest);
System.out.format("Translated Text: %s", response.getTranslationsList().get(0).getTranslatedText());
return response;
} catch (Exception e) {
throw new RuntimeException("Couldn't create client.", e);
}
}
use of com.google.cloud.tasks.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.
the class CreateKeyRing method createKeyRing.
// Create a new key ring.
public void createKeyRing(String projectId, String locationId, String id) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the parent name from the project and location.
LocationName locationName = LocationName.of(projectId, locationId);
// Build the key ring to create.
KeyRing keyRing = KeyRing.newBuilder().build();
// Create the key ring.
KeyRing createdKeyRing = client.createKeyRing(locationName, id, keyRing);
System.out.printf("Created key ring %s%n", createdKeyRing.getName());
}
}
use of com.google.cloud.tasks.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method quickstart.
public void quickstart(String projectId, String locationId) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the parent from the project and location.
LocationName parent = LocationName.of(projectId, locationId);
// Call the API.
ListKeyRingsPagedResponse response = client.listKeyRings(parent);
// Iterate over each key ring and print its name.
System.out.println("key rings:");
for (KeyRing keyRing : response.iterateAll()) {
System.out.printf("%s%n", keyRing.getName());
}
}
}
Aggregations