@Test public void isContainerRunningDeleted () { String zone = "my-zone"; String uniqueId = "my-unique-id"; GcpComputeInstanceContainer container = GcpComputeInstanceContainer.builder() .withUniqueIdentifier(uniqueId) .withZone(zone) .build(); ProjectZoneInstanceName instance = ProjectZoneInstanceName.newBuilder() .setProject(MY_AWESOME_PROJECT) .setZone(zone) .setInstance(uniqueId) .build(); doThrow(new ApiException(new RuntimeException(), new StatusCode() { @Override public Code getCode () { return Code.NOT_FOUND; } @Override public Object getTransportCode () { return null; } }, false)).when(instanceClient).getInstance(instance); assertEquals(ContainerHealth.DOES_NOT_EXIST, gcpComputePlatform.isContainerRunning(container)); }
public ContainerHealth isContainerRunning (GcpComputeInstanceContainer gcpComputeInstanceContainer) { ProjectZoneInstanceName instanceName = getProjectZoneInstanceNameOfContainer(gcpComputeInstanceContainer, getProjectName()); Instance instance; try { instance = getInstanceClient().getInstance(instanceName); } catch (ApiException e) { return Optional.of(e) .map(ApiException::getStatusCode) .map(StatusCode::getCode) .filter(code -> code == StatusCode.Code.NOT_FOUND) .map(code -> ContainerHealth.DOES_NOT_EXIST) .orElse(ContainerHealth.RUNNING_EXPERIMENT); } String status = instance.getStatus(); return "RUNNING".equals(status) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public ContainerHealth isContainerRunning (GcpComputeInstanceContainer gcpComputeInstanceContainer) { ProjectZoneInstanceName instanceName = getProjectZoneInstanceNameOfContainer(gcpComputeInstanceContainer, getProjectName()); Instance instance; try { instance = getInstanceClient().getInstance(instanceName); } catch (ApiException e) { return Optional.of(e) .map(ApiException::getStatusCode) .map(StatusCode::getCode) .filter(code -> code == StatusCode.Code.NOT_FOUND) .map(code -> ContainerHealth.DOES_NOT_EXIST) .orElse(ContainerHealth.RUNNING_EXPERIMENT); } String status = instance.getStatus(); return "RUNNING".equals(status) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; } }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public ContainerHealth isContainerRunning (GcpComputeInstanceContainer gcpComputeInstanceContainer) { ProjectZoneInstanceName instanceName = getProjectZoneInstanceNameOfContainer(gcpComputeInstanceContainer, getProjectName()); Instance instance; try { instance = getInstanceClient().getInstance(instanceName); } catch (ApiException e) { return Optional.of(e) .map(ApiException::getStatusCode) .map(StatusCode::getCode) .filter(code -> code == StatusCode.Code.NOT_FOUND) .map(code -> ContainerHealth.DOES_NOT_EXIST) .orElse(ContainerHealth.RUNNING_EXPERIMENT); } String status = instance.getStatus(); return "RUNNING".equals(status) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; }  }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public ContainerHealth isContainerRunning (GcpComputeInstanceContainer gcpComputeInstanceContainer) { ProjectZoneInstanceName instanceName = getProjectZoneInstanceNameOfContainer(gcpComputeInstanceContainer, getProjectName()); Instance instance; try { instance = getInstanceClient().getInstance(instanceName); } catch (ApiException e) { return Optional.of(e) .map(ApiException::getStatusCode) .map(StatusCode::getCode) .filter(code -> code == StatusCode.Code.NOT_FOUND) .map(code -> ContainerHealth.DOES_NOT_EXIST) .orElse(ContainerHealth.RUNNING_EXPERIMENT); } String status = instance.getStatus(); return "RUNNING".equals(status) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; }  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 ContainerHealth isContainerRunning (GcpComputeInstanceContainer gcpComputeInstanceContainer) { ProjectZoneInstanceName instanceName = getProjectZoneInstanceNameOfContainer(gcpComputeInstanceContainer, getProjectName()); Instance instance; try { instance = getInstanceClient().getInstance(instanceName); } catch (ApiException e) { return Optional.of(e) .map(ApiException::getStatusCode) .map(StatusCode::getCode) .filter(code -> code == StatusCode.Code.NOT_FOUND) .map(code -> ContainerHealth.DOES_NOT_EXIST) .orElse(ContainerHealth.RUNNING_EXPERIMENT); } String status = instance.getStatus(); return "RUNNING".equals(status) ? ContainerHealth.NORMAL : ContainerHealth.RUNNING_EXPERIMENT; }  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);  }