@Test public void checkTags () { GcpComputeInstanceContainer container; Tags actualTags = Tags.newBuilder().addAllItems(List.of("HTTP", "HTTPS", "SSH")).build(); List<String> orderedTags, unorderedTags, differentTags; orderedTags = List.of("HTTP", "HTTPS", "SSH"); unorderedTags = List.of("SSH", "HTTPS", "HTTP"); differentTags = List.of("RDP", "NTP"); String instanceName = "0123456789"; String zone = "my-datacenter"; container = GcpComputeInstanceContainer.builder().withUniqueIdentifier(instanceName).withZone(zone).build(); ProjectZoneInstanceName instance = ProjectZoneInstanceName.of(instanceName, MY_AWESOME_PROJECT, zone); doReturn(Instance.newBuilder().setTags(actualTags).build()).when(instanceClient).getInstance(instance); assertTrue(gcpComputePlatform.checkTags(container, orderedTags)); assertTrue(gcpComputePlatform.checkTags(container, unorderedTags)); assertFalse(gcpComputePlatform.checkTags(container, differentTags)); }
public boolean checkTags (GcpComputeInstanceContainer container, List<String> expectedTags) { log.debug("Evaluating tags of {}, expecting {}", v(DATADOG_CONTAINER_KEY, container), expectedTags); ProjectZoneInstanceName instance = getProjectZoneInstanceNameOfContainer(container, getProjectName()); List<String> actualTags = getInstanceClient().getInstance(instance).getTags().getItemsList(); log.debug("Actual tags are {}", actualTags); actualTags = actualTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(actualTags); expectedTags = expectedTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(expectedTags); return actualTags.equals(expectedTags); }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public boolean checkTags (GcpComputeInstanceContainer container, List<String> expectedTags) { log.debug("Evaluating tags of {}, expecting {}", v(DATADOG_CONTAINER_KEY, container), expectedTags); ProjectZoneInstanceName instance = getProjectZoneInstanceNameOfContainer(container, getProjectName()); List<String> actualTags = getInstanceClient().getInstance(instance).getTags().getItemsList(); log.debug("Actual tags are {}", actualTags); actualTags = actualTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(actualTags); expectedTags = expectedTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(expectedTags); return actualTags.equals(expectedTags); } }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public boolean checkTags (GcpComputeInstanceContainer container, List<String> expectedTags) { log.debug("Evaluating tags of {}, expecting {}", v(DATADOG_CONTAINER_KEY, container), expectedTags); ProjectZoneInstanceName instance = getProjectZoneInstanceNameOfContainer(container, getProjectName()); List<String> actualTags = getInstanceClient().getInstance(instance).getTags().getItemsList(); log.debug("Actual tags are {}", actualTags); actualTags = actualTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(actualTags); expectedTags = expectedTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(expectedTags); return actualTags.equals(expectedTags); }  }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public boolean checkTags (GcpComputeInstanceContainer container, List<String> expectedTags) { log.debug("Evaluating tags of {}, expecting {}", v(DATADOG_CONTAINER_KEY, container), expectedTags); ProjectZoneInstanceName instance = getProjectZoneInstanceNameOfContainer(container, getProjectName()); List<String> actualTags = getInstanceClient().getInstance(instance).getTags().getItemsList(); log.debug("Actual tags are {}", actualTags); actualTags = actualTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(actualTags); expectedTags = expectedTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(expectedTags); return actualTags.equals(expectedTags); }  void setRoutableCIDRBlocks(Collection<String> routableCIDRBlocks); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); Collection<Items> getIncludeFilter(); void setIncludeFilter(Map<String, String> includeFilter); Collection<Items> getExcludeFilter(); void setExcludeFilter(Map<String, String> excludeFilter); @Override boolean isContainerRecycled(Container container); String stopInstance(GcpComputeInstanceContainer container); ContainerHealth isContainerRunning(GcpComputeInstanceContainer gcpComputeInstanceContainer); String simulateMaintenance(GcpComputeInstanceContainer container); String setTags(GcpComputeInstanceContainer container, List<String> tags); String setTagsSafe(GcpComputeInstanceContainer container, List<String> newTags, String oldFingerprint); boolean isContainerGroupAtCapacity(GcpComputeInstanceContainer container); boolean checkTags(GcpComputeInstanceContainer container, List<String> expectedTags); void startInstance(GcpComputeInstanceContainer container); String restartContainer(GcpComputeInstanceContainer container); String getBestEndpoint(String privateIPAddress, String publicIPAddress); boolean isAddressRoutable(String privateIPAddress); String getLatestInstanceId(String instanceName, String zone); Fingerprint<List<String>> getFirewallTags(GcpComputeInstanceContainer container); void setProjectId(String projectId); @Override String getEndpoint(GcpComputeInstanceContainer container); @Override SSHCredentials getSshCredentials(GcpComputeInstanceContainer container); @Override String getRunningDirectory(); @Override void recycleContainer(GcpComputeInstanceContainer container); String recreateInstanceInInstanceGroup(GcpComputeInstanceContainer container); boolean isOperationComplete(String operationId); }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public boolean checkTags (GcpComputeInstanceContainer container, List<String> expectedTags) { log.debug("Evaluating tags of {}, expecting {}", v(DATADOG_CONTAINER_KEY, container), expectedTags); ProjectZoneInstanceName instance = getProjectZoneInstanceNameOfContainer(container, getProjectName()); List<String> actualTags = getInstanceClient().getInstance(instance).getTags().getItemsList(); log.debug("Actual tags are {}", actualTags); actualTags = actualTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(actualTags); expectedTags = expectedTags == null ? Collections.emptyList() : Ordering.natural().sortedCopy(expectedTags); return actualTags.equals(expectedTags); }  void setRoutableCIDRBlocks(Collection<String> routableCIDRBlocks); @Override ApiStatus getApiStatus(); @Override PlatformLevel getPlatformLevel(); @Override PlatformHealth getPlatformHealth(); Collection<Items> getIncludeFilter(); void setIncludeFilter(Map<String, String> includeFilter); Collection<Items> getExcludeFilter(); void setExcludeFilter(Map<String, String> excludeFilter); @Override boolean isContainerRecycled(Container container); String stopInstance(GcpComputeInstanceContainer container); ContainerHealth isContainerRunning(GcpComputeInstanceContainer gcpComputeInstanceContainer); String simulateMaintenance(GcpComputeInstanceContainer container); String setTags(GcpComputeInstanceContainer container, List<String> tags); String setTagsSafe(GcpComputeInstanceContainer container, List<String> newTags, String oldFingerprint); boolean isContainerGroupAtCapacity(GcpComputeInstanceContainer container); boolean checkTags(GcpComputeInstanceContainer container, List<String> expectedTags); void startInstance(GcpComputeInstanceContainer container); String restartContainer(GcpComputeInstanceContainer container); String getBestEndpoint(String privateIPAddress, String publicIPAddress); boolean isAddressRoutable(String privateIPAddress); String getLatestInstanceId(String instanceName, String zone); Fingerprint<List<String>> getFirewallTags(GcpComputeInstanceContainer container); void setProjectId(String projectId); @Override String getEndpoint(GcpComputeInstanceContainer container); @Override SSHCredentials getSshCredentials(GcpComputeInstanceContainer container); @Override String getRunningDirectory(); @Override void recycleContainer(GcpComputeInstanceContainer container); String recreateInstanceInInstanceGroup(GcpComputeInstanceContainer container); boolean isOperationComplete(String operationId);  }