@Test public void isNotFiltered () { Items includeTags = Items.newBuilder().setKey("include").setValue("true").build(); Metadata includeMetadata = Metadata.newBuilder().addItems(includeTags).build(); Items excludeTags = Items.newBuilder().setKey("exclude").setValue("true").build(); Metadata excludeMetadata = Metadata.newBuilder().addItems(excludeTags).build(); Instance matchingInclude = Instance.newBuilder().setMetadata(includeMetadata).build(); Instance includeWithExclude = Instance.newBuilder(matchingInclude).setMetadata(excludeMetadata).build(); gcpComputePlatform.setIncludeFilter(Map.of("include", "true")); gcpComputePlatform.setExcludeFilter(Map.of("exclude", "true")); assertTrue(gcpComputePlatform.isNotFiltered(matchingInclude)); assertFalse(gcpComputePlatform.isNotFiltered(includeWithExclude)); }
boolean isNotFiltered (Instance instance) { List<Items> itemsList = Optional.of(instance) .map(Instance::getMetadata) .map(Metadata::getItemsList) .orElse(emptyList()); Collection<Items> includeFilter = getIncludeFilter(); Collection<Items> excludeFilter = getExcludeFilter(); boolean hasAllMustIncludes = includeFilter.isEmpty() || itemsList.stream().anyMatch(includeFilter::contains); boolean hasNoMustNotIncludes = itemsList.stream().noneMatch(excludeFilter::contains); final boolean isNotFiltered = hasAllMustIncludes && hasNoMustNotIncludes; if (!isNotFiltered) { log.info("Instance {} filtered because of {}, {}", instance.getName(), kv("includeFilter", hasAllMustIncludes), kv("excludeFilter", hasNoMustNotIncludes)); } return isNotFiltered; }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { boolean isNotFiltered (Instance instance) { List<Items> itemsList = Optional.of(instance) .map(Instance::getMetadata) .map(Metadata::getItemsList) .orElse(emptyList()); Collection<Items> includeFilter = getIncludeFilter(); Collection<Items> excludeFilter = getExcludeFilter(); boolean hasAllMustIncludes = includeFilter.isEmpty() || itemsList.stream().anyMatch(includeFilter::contains); boolean hasNoMustNotIncludes = itemsList.stream().noneMatch(excludeFilter::contains); final boolean isNotFiltered = hasAllMustIncludes && hasNoMustNotIncludes; if (!isNotFiltered) { log.info("Instance {} filtered because of {}, {}", instance.getName(), kv("includeFilter", hasAllMustIncludes), kv("excludeFilter", hasNoMustNotIncludes)); } return isNotFiltered; } }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { boolean isNotFiltered (Instance instance) { List<Items> itemsList = Optional.of(instance) .map(Instance::getMetadata) .map(Metadata::getItemsList) .orElse(emptyList()); Collection<Items> includeFilter = getIncludeFilter(); Collection<Items> excludeFilter = getExcludeFilter(); boolean hasAllMustIncludes = includeFilter.isEmpty() || itemsList.stream().anyMatch(includeFilter::contains); boolean hasNoMustNotIncludes = itemsList.stream().noneMatch(excludeFilter::contains); final boolean isNotFiltered = hasAllMustIncludes && hasNoMustNotIncludes; if (!isNotFiltered) { log.info("Instance {} filtered because of {}, {}", instance.getName(), kv("includeFilter", hasAllMustIncludes), kv("excludeFilter", hasNoMustNotIncludes)); } return isNotFiltered; }  }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { boolean isNotFiltered (Instance instance) { List<Items> itemsList = Optional.of(instance) .map(Instance::getMetadata) .map(Metadata::getItemsList) .orElse(emptyList()); Collection<Items> includeFilter = getIncludeFilter(); Collection<Items> excludeFilter = getExcludeFilter(); boolean hasAllMustIncludes = includeFilter.isEmpty() || itemsList.stream().anyMatch(includeFilter::contains); boolean hasNoMustNotIncludes = itemsList.stream().noneMatch(excludeFilter::contains); final boolean isNotFiltered = hasAllMustIncludes && hasNoMustNotIncludes; if (!isNotFiltered) { log.info("Instance {} filtered because of {}, {}", instance.getName(), kv("includeFilter", hasAllMustIncludes), kv("excludeFilter", hasNoMustNotIncludes)); } return isNotFiltered; }  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> { boolean isNotFiltered (Instance instance) { List<Items> itemsList = Optional.of(instance) .map(Instance::getMetadata) .map(Metadata::getItemsList) .orElse(emptyList()); Collection<Items> includeFilter = getIncludeFilter(); Collection<Items> excludeFilter = getExcludeFilter(); boolean hasAllMustIncludes = includeFilter.isEmpty() || itemsList.stream().anyMatch(includeFilter::contains); boolean hasNoMustNotIncludes = itemsList.stream().noneMatch(excludeFilter::contains); final boolean isNotFiltered = hasAllMustIncludes && hasNoMustNotIncludes; if (!isNotFiltered) { log.info("Instance {} filtered because of {}, {}", instance.getName(), kv("includeFilter", hasAllMustIncludes), kv("excludeFilter", hasNoMustNotIncludes)); } return isNotFiltered; }  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);  }