-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(bazel): update protobuf to v3.21.7 (#754)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 477955264 Source-Link: https://togithub.com/googleapis/googleapis/commit/a724450af76d0001f23602684c49cd6a4b3a5654 Source-Link: https://togithub.com/googleapis/googleapis-gen/commit/4abcbcaec855e74a0b22a4988cf9e0eb61a83094 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGFiY2JjYWVjODU1ZTc0YTBiMjJhNDk4OGNmOWUwZWI2MWE4MzA5NCJ9
- Loading branch information
1 parent
2bfab44
commit 5cde0a4
Showing
1,299 changed files
with
90,575 additions
and
130,853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...pute/google-cloud-compute/src/test/java/com/google/cloud/compute/v1/integration/Util.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2021 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.cloud.compute.v1.integration; | ||
|
||
import com.google.cloud.compute.v1.Address; | ||
import com.google.cloud.compute.v1.AddressesClient; | ||
import com.google.cloud.compute.v1.DeleteInstanceRequest; | ||
import com.google.cloud.compute.v1.Instance; | ||
import com.google.cloud.compute.v1.InstancesClient; | ||
import com.google.cloud.compute.v1.InstancesClient.ListPagedResponse; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZonedDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
|
||
public class Util { | ||
|
||
// Cleans existing test resources if any. | ||
private static final int DELETION_THRESHOLD_TIME_HOURS = 24; | ||
|
||
/** Bring down any instances that are older than 24 hours */ | ||
public static void cleanUpComputeInstances( | ||
InstancesClient instancesClient, String project, String zone, String prefix) { | ||
ListPagedResponse listPagedResponse = instancesClient.list(project, zone); | ||
for (Instance instance : listPagedResponse.iterateAll()) { | ||
if (isCreatedBeforeThresholdTime( | ||
ZonedDateTime.parse(instance.getCreationTimestamp()).toInstant()) | ||
&& instance.getName().startsWith(prefix)) { | ||
instancesClient.deleteAsync( | ||
DeleteInstanceRequest.newBuilder() | ||
.setInstance(instance.getName()) | ||
.setProject(project) | ||
.setZone(zone) | ||
.build()); | ||
} | ||
} | ||
} | ||
|
||
/** Bring down any addresses that are older than 24 hours */ | ||
public static void cleanUpComputeAddresses( | ||
AddressesClient addressesClient, String project, String region, String prefix) { | ||
AddressesClient.ListPagedResponse listPagedResponse = addressesClient.list(project, region); | ||
for (Address address : listPagedResponse.iterateAll()) { | ||
if (isCreatedBeforeThresholdTime(address.getCreationTimestamp()) | ||
&& address.getName().startsWith(prefix)) { | ||
addressesClient.deleteAsync(project, region, address.getName()); | ||
} | ||
} | ||
} | ||
|
||
private static boolean isCreatedBeforeThresholdTime(Instant instant) { | ||
return instant.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); | ||
} | ||
|
||
private static boolean isCreatedBeforeThresholdTime(String timestamp) { | ||
return OffsetDateTime.parse(timestamp) | ||
.toInstant() | ||
.isBefore(Instant.now().minus(DELETION_THRESHOLD_TIME_HOURS, ChronoUnit.HOURS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.