use of com.google.cloud.redis.v1beta1.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method getInstanceTest.
@Test
public void getInstanceTest() throws Exception {
Instance expectedResponse = Instance.newBuilder().setName(InstanceName.of("[PROJECT]", "[INSTANCE]").toString()).setDisplayName("displayName1714148973").putAllLabels(new HashMap<String, String>()).setCreateTime(Timestamp.newBuilder().build()).build();
mockBigtableInstanceAdmin.addResponse(expectedResponse);
InstanceName name = InstanceName.of("[PROJECT]", "[INSTANCE]");
Instance actualResponse = client.getInstance(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockBigtableInstanceAdmin.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetInstanceRequest actualRequest = ((GetInstanceRequest) actualRequests.get(0));
Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.cloud.redis.v1beta1.Instance in project java-bigtable by googleapis.
the class BaseBigtableInstanceAdminClientTest method createInstanceExceptionTest2.
@Test
public void createInstanceExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockBigtableInstanceAdmin.addException(exception);
try {
String parent = "parent-995424086";
String instanceId = "instanceId902024336";
Instance instance = Instance.newBuilder().build();
Map<String, Cluster> clusters = new HashMap<>();
client.createInstanceAsync(parent, instanceId, instance, clusters).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
InvalidArgumentException apiException = ((InvalidArgumentException) e.getCause());
Assert.assertEquals(StatusCode.Code.INVALID_ARGUMENT, apiException.getStatusCode().getCode());
}
}
use of com.google.cloud.redis.v1beta1.Instance in project TOSCAna by StuPro-TOSCAna.
the class CloudFormationVisitor method createSqlEc2.
/**
* Creates a EC2 for a {@link MysqlDatabase} that runs an initial sql query.
*
* @param mysqlDatabase the {@link MysqlDatabase} this sql query should be run on
* @param sqlQuery the sql query to run
* @return the instance name of the created EC2 Instance
*/
protected String createSqlEc2(MysqlDatabase mysqlDatabase, String sqlQuery) {
String ec2Name = toAlphanumerical(mysqlDatabase.getEntityName()) + "TmpSqlServer";
SecurityGroup webServerSecurityGroup = cfnModule.resource(SecurityGroup.class, ec2Name + SECURITY_GROUP).groupDescription("Temporary group for accessing mysqlDatabase" + toAlphanumerical(mysqlDatabase.getEntityName()) + " with SQLRequest");
cfnModule.resource(Instance.class, ec2Name).securityGroupIds(webServerSecurityGroup).imageId("ami-79873901").instanceType("t2.micro").instanceInitiatedShutdownBehavior("terminate").userData(new UserData(StackUtils.getUserDataDBConnFn(mysqlDatabase, sqlQuery)));
return ec2Name;
}
use of com.google.cloud.redis.v1beta1.Instance in project TOSCAna by StuPro-TOSCAna.
the class CloudFormationModule method build.
/**
* Build the template.
* <br>
* Following steps are taken:
* <ol>
* <li>Add CFNInit to corresponding instance resource </li>
* <li>Check if EC2 instances need access to S3. If yes, then
* <ol>
* <li>Add necessary IAM resources to the module</li>
* <li>Add <tt>Authentication<tt> and <tt>IamInstanceProfile<tt> to corresponding instance resource</li>
* </ol>
* </li>
* <li>Add the KeyPair to the template if it is needed</li>
* </ol>
*/
@Override
public void build() {
for (Map.Entry<String, CFNInit> pair : cfnInitMap.entrySet()) {
Resource res = this.getResource(pair.getKey());
if (res instanceof Instance) {
Instance instance = (Instance) res;
if (!pair.getValue().getConfigs().isEmpty()) {
instance.addCFNInit(pair.getValue()).userData(new UserData(getUserDataFn(pair.getKey(), CONFIG_SETS, this)));
}
}
}
if (!fileUploadList.isEmpty()) {
Role instanceRole = getS3InstanceRole(this);
getS3Policy(this).roles(instanceRole);
getS3InstanceProfile(this).roles(instanceRole);
Authentication s3authentication = getS3Authentication(bucketName);
for (String instanceName : authenticationSet) {
Resource res = this.getResource(instanceName);
if (res instanceof Instance) {
Instance instance = (Instance) res;
instance.authentication(s3authentication).iamInstanceProfile(ref(INSTANCE_PROFILE));
}
}
}
if (this.hasKeyPair()) {
strParam(KEYNAME).type(KEYNAME_TYPE).description(KEYNAME_DESCRIPTION).constraintDescription(KEYNAME_CONSTRAINT_DESCRIPTION);
}
}
use of com.google.cloud.redis.v1beta1.Instance in project java-docs-samples by GoogleCloudPlatform.
the class CreateWindowsServerInstanceInternalIp method createWindowsServerInstanceInternalIp.
// Creates a new Windows Server instance that has only an internal IP address.
public static void createWindowsServerInstanceInternalIp(String projectId, String zone, String instanceName, String networkLink, String subnetworkLink) throws IOException, ExecutionException, InterruptedException, TimeoutException {
// machineType - Machine type you want to create in following format:
// * "zones/{zone}/machineTypes/{type_name}". For example:
// * "zones/europe-west3-c/machineTypes/f1-micro"
// * You can find the list of available machine types using:
// * https://cloud.google.com/sdk/gcloud/reference/compute/machine-types/list
String machineType = "n1-standard-1";
// sourceImageFamily - Name of the public image family for Windows Server or SQL Server images.
// * https://cloud.google.com/compute/docs/images#os-compute-support
String sourceImageFamily = "windows-2012-r2";
// Instantiates a client.
try (InstancesClient instancesClient = InstancesClient.create()) {
AttachedDisk attachedDisk = AttachedDisk.newBuilder().setInitializeParams(AttachedDiskInitializeParams.newBuilder().setDiskSizeGb(64).setSourceImage(String.format("projects/windows-cloud/global/images/family/%s", sourceImageFamily)).build()).setAutoDelete(true).setBoot(true).setType(AttachedDisk.Type.PERSISTENT.toString()).build();
Instance instance = Instance.newBuilder().setName(instanceName).setMachineType(String.format("zones/%s/machineTypes/%s", zone, machineType)).addDisks(attachedDisk).addNetworkInterfaces(NetworkInterface.newBuilder().setName(networkLink).setSubnetwork(subnetworkLink).build()).build();
InsertInstanceRequest request = InsertInstanceRequest.newBuilder().setProject(projectId).setZone(zone).setInstanceResource(instance).build();
// Wait for the operation to complete.
Operation operation = instancesClient.insertAsync(request).get(3, TimeUnit.MINUTES);
if (operation.hasError()) {
System.out.printf("Error in creating instance %s", operation.getError());
return;
}
System.out.printf("Instance created %s", instanceName);
}
}
Aggregations