use of com.google.cloud.dataproc.v1.Cluster in project grpc-java by grpc.
the class ClientXdsClient method handleCdsResponse.
@Override
public void handleCdsResponse(ServerInfo serverInfo, String versionInfo, List<Any> resources, String nonce) {
syncContext.throwIfNotInThisSynchronizationContext();
Map<String, ParsedResource> parsedResources = new HashMap<>(resources.size());
Set<String> unpackedResources = new HashSet<>(resources.size());
Set<String> invalidResources = new HashSet<>();
List<String> errors = new ArrayList<>();
Set<String> retainedEdsResources = new HashSet<>();
for (int i = 0; i < resources.size(); i++) {
Any resource = resources.get(i);
// Unpack the Cluster.
Cluster cluster;
try {
cluster = unpackCompatibleType(resource, Cluster.class, ResourceType.CDS.typeUrl(), ResourceType.CDS.typeUrlV2());
} catch (InvalidProtocolBufferException e) {
errors.add("CDS response Resource index " + i + " - can't decode Cluster: " + e);
continue;
}
if (!isResourceNameValid(cluster.getName(), resource.getTypeUrl())) {
errors.add("Unsupported resource name: " + cluster.getName() + " for type: " + ResourceType.CDS);
continue;
}
String clusterName = canonifyResourceName(cluster.getName());
// unrequested resources.
if (!cdsResourceSubscribers.containsKey(clusterName)) {
continue;
}
unpackedResources.add(clusterName);
// Process Cluster into CdsUpdate.
CdsUpdate cdsUpdate;
try {
Set<String> certProviderInstances = null;
if (getBootstrapInfo() != null && getBootstrapInfo().certProviders() != null) {
certProviderInstances = getBootstrapInfo().certProviders().keySet();
}
cdsUpdate = processCluster(cluster, retainedEdsResources, certProviderInstances, serverInfo);
} catch (ResourceInvalidException e) {
errors.add("CDS response Cluster '" + clusterName + "' validation error: " + e.getMessage());
invalidResources.add(clusterName);
continue;
}
parsedResources.put(clusterName, new ParsedResource(cdsUpdate, resource));
}
logger.log(XdsLogLevel.INFO, "Received CDS Response version {0} nonce {1}. Parsed resources: {2}", versionInfo, nonce, unpackedResources);
handleResourceUpdate(serverInfo, ResourceType.CDS, parsedResources, invalidResources, retainedEdsResources, versionInfo, nonce, errors);
}
use of com.google.cloud.dataproc.v1.Cluster in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseCluster_validateEdsSourceConfig.
@Test
public void parseCluster_validateEdsSourceConfig() throws ResourceInvalidException {
Set<String> retainedEdsResources = new HashSet<>();
Cluster cluster1 = Cluster.newBuilder().setName("cluster-foo.googleapis.com").setType(DiscoveryType.EDS).setEdsClusterConfig(EdsClusterConfig.newBuilder().setEdsConfig(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance())).setServiceName("service-foo.googleapis.com")).setLbPolicy(LbPolicy.ROUND_ROBIN).build();
ClientXdsClient.processCluster(cluster1, retainedEdsResources, null, LRS_SERVER_INFO);
Cluster cluster2 = Cluster.newBuilder().setName("cluster-foo.googleapis.com").setType(DiscoveryType.EDS).setEdsClusterConfig(EdsClusterConfig.newBuilder().setEdsConfig(ConfigSource.newBuilder().setSelf(SelfConfigSource.getDefaultInstance())).setServiceName("service-foo.googleapis.com")).setLbPolicy(LbPolicy.ROUND_ROBIN).build();
ClientXdsClient.processCluster(cluster2, retainedEdsResources, null, LRS_SERVER_INFO);
Cluster cluster3 = Cluster.newBuilder().setName("cluster-foo.googleapis.com").setType(DiscoveryType.EDS).setEdsClusterConfig(EdsClusterConfig.newBuilder().setEdsConfig(ConfigSource.newBuilder().setPath("foo-path")).setServiceName("service-foo.googleapis.com")).setLbPolicy(LbPolicy.ROUND_ROBIN).build();
thrown.expect(ResourceInvalidException.class);
thrown.expectMessage("Cluster cluster-foo.googleapis.com: field eds_cluster_config must be set to indicate to" + " use EDS over ADS or self ConfigSource");
ClientXdsClient.processCluster(cluster3, retainedEdsResources, null, LRS_SERVER_INFO);
}
use of com.google.cloud.dataproc.v1.Cluster in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseCluster_leastRequestLbPolicy_defaultLbConfig.
@Test
public void parseCluster_leastRequestLbPolicy_defaultLbConfig() throws ResourceInvalidException {
ClientXdsClient.enableLeastRequest = true;
Cluster cluster = Cluster.newBuilder().setName("cluster-foo.googleapis.com").setType(DiscoveryType.EDS).setEdsClusterConfig(EdsClusterConfig.newBuilder().setEdsConfig(ConfigSource.newBuilder().setAds(AggregatedConfigSource.getDefaultInstance())).setServiceName("service-foo.googleapis.com")).setLbPolicy(LbPolicy.LEAST_REQUEST).build();
CdsUpdate update = ClientXdsClient.processCluster(cluster, new HashSet<String>(), null, LRS_SERVER_INFO);
assertThat(update.lbPolicy()).isEqualTo(CdsUpdate.LbPolicy.LEAST_REQUEST);
assertThat(update.choiceCount()).isEqualTo(ClientXdsClient.DEFAULT_LEAST_REQUEST_CHOICE_COUNT);
}
use of com.google.cloud.dataproc.v1.Cluster in project java-docs-samples by GoogleCloudPlatform.
the class BulkWrite method getClusterNodeCount.
// Get the number of nodes for the Bigtable instance. This only works for single cluster instances
// so it will treat multi-cluster instances as single node clusters.
private static int getClusterNodeCount(String projectId, String instanceId) throws IOException, GeneralSecurityException {
try {
BigtableClusterUtilities clusterUtility = BigtableClusterUtilities.forInstance(projectId, instanceId);
Cluster cluster = clusterUtility.getSingleCluster();
String clusterId = new BigtableClusterName(cluster.getName()).getClusterId();
String zoneId = BigtableClusterUtilities.getZoneId(cluster);
int clusterNodeCount = clusterUtility.getClusterNodeCount(clusterId, zoneId);
System.out.println("Cluster size " + clusterNodeCount);
return clusterNodeCount;
} catch (IllegalStateException e) {
System.out.println("Unable to get cluster size. Treating as single-node cluster.");
return 1;
}
}
use of com.google.cloud.dataproc.v1.Cluster in project cdap by caskdata.
the class DataprocClient method getClusterControllerClient.
/*
* Using the input Google Credentials retrieve the Dataproc Cluster controller client
*/
private static ClusterControllerClient getClusterControllerClient(DataprocConf conf) throws IOException {
CredentialsProvider credentialsProvider = FixedCredentialsProvider.create(conf.getDataprocCredentials());
String rootUrl = Optional.ofNullable(conf.getRootUrl()).orElse(ClusterControllerSettings.getDefaultEndpoint());
String regionalEndpoint = conf.getRegion() + "-" + rootUrl;
ClusterControllerSettings controllerSettings = ClusterControllerSettings.newBuilder().setCredentialsProvider(credentialsProvider).setEndpoint(regionalEndpoint).build();
return ClusterControllerClient.create(controllerSettings);
}
Aggregations