@Test public void recreateInstanceInRegionalInstanceGroup () { String uuid = "12345678901234567890"; String instanceName = "my-awesome-instance"; String zone = "my-datacenter"; String region = "my-city"; String instanceGroup = "my-high-availability-group"; ProjectRegionInstanceGroupManagerName groupManagerName = ProjectRegionInstanceGroupManagerName.of(instanceGroup, MY_AWESOME_PROJECT, region); String createdBy = groupManagerName.toString(); GcpComputeInstanceContainer container = GcpComputeInstanceContainer.builder() .withCreatedBy(createdBy) .withZone(zone) .withPlatform(gcpComputePlatform) .withInstanceName(instanceName) .withUniqueIdentifier(uuid) .build(); ArgumentCaptor<RegionInstanceGroupManagersRecreateRequest> request = ArgumentCaptor.forClass( RegionInstanceGroupManagersRecreateRequest.class); String operationSelfLink = "my-operation-self-link"; Operation operation = Operation.newBuilder().setSelfLink(operationSelfLink).build(); doReturn(operation).when(regionInstanceGroupManagerClient) .recreateInstancesRegionInstanceGroupManager(any(ProjectRegionInstanceGroupManagerName.class), request.capture()); assertEquals(operationSelfLink, gcpComputePlatform.recreateInstanceInInstanceGroup(container)); assertThat(request.getValue().getInstancesList(), containsInAnyOrder(ProjectZoneInstanceName.of(instanceName, MY_AWESOME_PROJECT, zone).toString())); }
public String recreateInstanceInInstanceGroup (GcpComputeInstanceContainer container) { String group = getContainerGroup(container); String instanceName = ProjectZoneInstanceName.newBuilder() .setInstance(container.getInstanceName()) .setZone(container.getZone()) .setProject(getProjectName().getProject()) .build() .toString(); if (ProjectZoneInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInZoneInstanceGroup(instanceName, group); else if (ProjectRegionInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInRegionInstanceGroup(instanceName, group); throw new ChaosException(GCP_COMPUTE_GENERIC_ERROR); }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public String recreateInstanceInInstanceGroup (GcpComputeInstanceContainer container) { String group = getContainerGroup(container); String instanceName = ProjectZoneInstanceName.newBuilder() .setInstance(container.getInstanceName()) .setZone(container.getZone()) .setProject(getProjectName().getProject()) .build() .toString(); if (ProjectZoneInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInZoneInstanceGroup(instanceName, group); else if (ProjectRegionInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInRegionInstanceGroup(instanceName, group); throw new ChaosException(GCP_COMPUTE_GENERIC_ERROR); } }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public String recreateInstanceInInstanceGroup (GcpComputeInstanceContainer container) { String group = getContainerGroup(container); String instanceName = ProjectZoneInstanceName.newBuilder() .setInstance(container.getInstanceName()) .setZone(container.getZone()) .setProject(getProjectName().getProject()) .build() .toString(); if (ProjectZoneInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInZoneInstanceGroup(instanceName, group); else if (ProjectRegionInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInRegionInstanceGroup(instanceName, group); throw new ChaosException(GCP_COMPUTE_GENERIC_ERROR); }  }
GcpComputePlatform extends Platform implements SshBasedExperiment<GcpComputeInstanceContainer> { public String recreateInstanceInInstanceGroup (GcpComputeInstanceContainer container) { String group = getContainerGroup(container); String instanceName = ProjectZoneInstanceName.newBuilder() .setInstance(container.getInstanceName()) .setZone(container.getZone()) .setProject(getProjectName().getProject()) .build() .toString(); if (ProjectZoneInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInZoneInstanceGroup(instanceName, group); else if (ProjectRegionInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInRegionInstanceGroup(instanceName, group); throw new ChaosException(GCP_COMPUTE_GENERIC_ERROR); }  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 String recreateInstanceInInstanceGroup (GcpComputeInstanceContainer container) { String group = getContainerGroup(container); String instanceName = ProjectZoneInstanceName.newBuilder() .setInstance(container.getInstanceName()) .setZone(container.getZone()) .setProject(getProjectName().getProject()) .build() .toString(); if (ProjectZoneInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInZoneInstanceGroup(instanceName, group); else if (ProjectRegionInstanceGroupManagerName.isParsableFrom(group)) return recreateInstanceInRegionInstanceGroup(instanceName, group); throw new ChaosException(GCP_COMPUTE_GENERIC_ERROR); }  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);  }