Search in sources :

Example 56 with Instance

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()));
}
Also used : InstanceName(com.google.bigtable.admin.v2.InstanceName) AbstractMessage(com.google.protobuf.AbstractMessage) GetInstanceRequest(com.google.bigtable.admin.v2.GetInstanceRequest) Instance(com.google.bigtable.admin.v2.Instance) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 57 with Instance

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());
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) Instance(com.google.bigtable.admin.v2.Instance) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) Cluster(com.google.bigtable.admin.v2.Cluster) ByteString(com.google.protobuf.ByteString) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 58 with Instance

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;
}
Also used : Instance(com.scaleset.cfbuilder.ec2.Instance) UserData(com.scaleset.cfbuilder.ec2.UserData) SecurityGroup(com.scaleset.cfbuilder.ec2.SecurityGroup)

Example 59 with Instance

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);
    }
}
Also used : AuthenticationUtils.getS3InstanceRole(org.opentosca.toscana.plugins.cloudformation.util.AuthenticationUtils.getS3InstanceRole) Role(com.scaleset.cfbuilder.iam.Role) Instance(com.scaleset.cfbuilder.ec2.Instance) UserData(com.scaleset.cfbuilder.ec2.UserData) AuthenticationUtils.getS3Authentication(org.opentosca.toscana.plugins.cloudformation.util.AuthenticationUtils.getS3Authentication) Authentication(com.scaleset.cfbuilder.cloudformation.Authentication) Resource(com.scaleset.cfbuilder.core.Resource) CFNInit(com.scaleset.cfbuilder.ec2.metadata.CFNInit) HashMap(java.util.HashMap) Map(java.util.Map)

Example 60 with Instance

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);
    }
}
Also used : InsertInstanceRequest(com.google.cloud.compute.v1.InsertInstanceRequest) Instance(com.google.cloud.compute.v1.Instance) InstancesClient(com.google.cloud.compute.v1.InstancesClient) AttachedDisk(com.google.cloud.compute.v1.AttachedDisk) Operation(com.google.cloud.compute.v1.Operation)

Aggregations

Test (org.junit.Test)43 CloudRedisClient (com.google.cloud.redis.v1beta1.CloudRedisClient)42 Instance (com.google.cloud.redis.v1beta1.Instance)34 Instance (com.google.cloud.compute.v1.Instance)25 InstancesClient (com.google.cloud.compute.v1.InstancesClient)19 AbstractMessage (com.google.protobuf.AbstractMessage)17 ByteString (com.google.protobuf.ByteString)17 Operation (com.google.cloud.compute.v1.Operation)13 Instance (com.google.spanner.admin.instance.v1.Instance)11 Instance (com.google.bigtable.admin.v2.Instance)10 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)10 Operation (com.google.longrunning.Operation)10 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)9 Instance (com.google.cloud.notebooks.v1beta1.Instance)9 Any (com.google.protobuf.Any)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)7 FieldMask (com.google.protobuf.FieldMask)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 ArrayList (java.util.ArrayList)7 NetworkInterface (com.google.cloud.compute.v1.NetworkInterface)6