Search in sources :

Example 1 with ProjectBillingInfo

use of com.google.cloud.billing.v1.ProjectBillingInfo in project terra-resource-buffer by DataBiosphere.

the class SetBillingInfoStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) {
    // Skip if billing account is not set.
    if (gcpProjectConfig.getBillingAccount() == null || gcpProjectConfig.getBillingAccount().isEmpty()) {
        return StepResult.getStepResultSuccess();
    }
    String projectId = flightContext.getWorkingMap().get(GOOGLE_PROJECT_ID, String.class);
    ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName("billingAccounts/" + gcpProjectConfig.getBillingAccount()).build();
    billingCow.updateProjectBillingInfo(projectIdToName(projectId), setBilling);
    return StepResult.getStepResultSuccess();
}
Also used : ProjectBillingInfo(com.google.cloud.billing.v1.ProjectBillingInfo)

Example 2 with ProjectBillingInfo

use of com.google.cloud.billing.v1.ProjectBillingInfo in project terra-cloud-resource-lib by DataBiosphere.

the class CloudBillingUtils method setDefaultProjectBilling.

/**
 * Sets the projects billing account with the default billing used for test.
 */
public static void setDefaultProjectBilling(String projectId) throws Exception {
    ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName(BILLING_ACCOUNT_NAME).build();
    getBillingClientCow().updateProjectBillingInfo("projects/" + projectId, setBilling);
    // Sleep for 1s to make sure billing is ready.
    Thread.sleep(1000);
}
Also used : ProjectBillingInfo(com.google.cloud.billing.v1.ProjectBillingInfo)

Example 3 with ProjectBillingInfo

use of com.google.cloud.billing.v1.ProjectBillingInfo in project java-billing by googleapis.

the class CloudBillingClientTest method listProjectBillingInfoTest2.

@Test
public void listProjectBillingInfoTest2() throws Exception {
    ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build();
    ListProjectBillingInfoResponse expectedResponse = ListProjectBillingInfoResponse.newBuilder().setNextPageToken("").addAllProjectBillingInfo(Arrays.asList(responsesElement)).build();
    mockCloudBilling.addResponse(expectedResponse);
    String name = "name3373707";
    ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name);
    List<ProjectBillingInfo> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCloudBilling.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListProjectBillingInfoRequest actualRequest = ((ListProjectBillingInfoRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListProjectBillingInfoPagedResponse(com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 4 with ProjectBillingInfo

use of com.google.cloud.billing.v1.ProjectBillingInfo in project java-billing by googleapis.

the class CloudBillingClientTest method listProjectBillingInfoTest.

@Test
public void listProjectBillingInfoTest() throws Exception {
    ProjectBillingInfo responsesElement = ProjectBillingInfo.newBuilder().build();
    ListProjectBillingInfoResponse expectedResponse = ListProjectBillingInfoResponse.newBuilder().setNextPageToken("").addAllProjectBillingInfo(Arrays.asList(responsesElement)).build();
    mockCloudBilling.addResponse(expectedResponse);
    BillingAccountName name = BillingAccountName.of("[BILLING_ACCOUNT]");
    ListProjectBillingInfoPagedResponse pagedListResponse = client.listProjectBillingInfo(name);
    List<ProjectBillingInfo> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getProjectBillingInfoList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockCloudBilling.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListProjectBillingInfoRequest actualRequest = ((ListProjectBillingInfoRequest) actualRequests.get(0));
    Assert.assertEquals(name.toString(), actualRequest.getName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListProjectBillingInfoPagedResponse(com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse) Test(org.junit.Test)

Example 5 with ProjectBillingInfo

use of com.google.cloud.billing.v1.ProjectBillingInfo in project terra-workspace-manager by DataBiosphere.

the class SetProjectBillingStep method doStep.

@Override
public StepResult doStep(FlightContext flightContext) {
    String projectId = flightContext.getWorkingMap().get(WorkspaceFlightMapKeys.GCP_PROJECT_ID, String.class);
    String billingAccountId = flightContext.getWorkingMap().get(WorkspaceFlightMapKeys.BILLING_ACCOUNT_ID, String.class);
    ProjectBillingInfo setBilling = ProjectBillingInfo.newBuilder().setBillingAccountName("billingAccounts/" + billingAccountId).build();
    billingClient.updateProjectBillingInfo("projects/" + projectId, setBilling);
    return StepResult.getStepResultSuccess();
}
Also used : ProjectBillingInfo(com.google.cloud.billing.v1.ProjectBillingInfo)

Aggregations

ProjectBillingInfo (com.google.cloud.billing.v1.ProjectBillingInfo)4 ListProjectBillingInfoPagedResponse (com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse)2 AbstractMessage (com.google.protobuf.AbstractMessage)2 Test (org.junit.Test)2 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)1 ByteString (com.google.protobuf.ByteString)1 Test (org.junit.jupiter.api.Test)1