use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilder method getNetworkInterface.
private List<NetworkInterface> getNetworkInterface(Iterable<CloudResource> networkResources, Iterable<CloudResource> computeResources, Region region, Group group, Compute compute, String projectId, boolean noPublicIp) throws IOException {
NetworkInterface networkInterface = new NetworkInterface();
List<CloudResource> subnet = filterResourcesByType(networkResources, ResourceType.GCP_SUBNET);
String networkName = subnet.isEmpty() ? filterResourcesByType(networkResources, ResourceType.GCP_NETWORK).get(0).getName() : subnet.get(0).getName();
networkInterface.setName(networkName);
if (!noPublicIp) {
AccessConfig accessConfig = new AccessConfig();
accessConfig.setName(networkName);
accessConfig.setType("ONE_TO_ONE_NAT");
List<CloudResource> reservedIp = filterResourcesByType(computeResources, ResourceType.GCP_RESERVED_IP);
if (InstanceGroupType.GATEWAY == group.getType() && !reservedIp.isEmpty()) {
Addresses.Get getReservedIp = compute.addresses().get(projectId, region.value(), reservedIp.get(0).getName());
accessConfig.setNatIP(getReservedIp.execute().getAddress());
}
networkInterface.setAccessConfigs(Collections.singletonList(accessConfig));
}
if (subnet.isEmpty()) {
networkInterface.setNetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/global/networks/%s", projectId, networkName));
} else {
networkInterface.setSubnetwork(String.format("https://www.googleapis.com/compute/v1/projects/%s/regions/%s/subnetworks/%s", projectId, region.value(), networkName));
}
return Collections.singletonList(networkInterface);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method setUp.
@Before
public void setUp() {
privateId = 0L;
name = "master";
flavor = "m1.medium";
instanceId = "SOME_ID";
volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
security = new Security(rules, null);
Location location = Location.location(Region.region("region"), AvailabilityZone.availabilityZone("az"));
Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
CloudContext cloudContext = new CloudContext(privateId, "testname", "GCP", "owner");
CloudCredential cloudCredential = new CloudCredential(privateId, "credentialname");
cloudCredential.putParameter("projectId", "projectId");
String projectId = GcpStackUtil.getProjectId(cloudCredential);
String serviceAccountId = GcpStackUtil.getServiceAccountId(cloudCredential);
authenticatedContext = new AuthenticatedContext(cloudContext, cloudCredential);
context = new GcpContext(cloudContext.getName(), location, projectId, serviceAccountId, compute, false, 30, false);
List<CloudResource> networkResources = Arrays.asList(new Builder().type(ResourceType.GCP_NETWORK).name("network-test").build());
context.addNetworkResources(networkResources);
operation = new Operation();
operation.setName("operation");
operation.setHttpErrorStatusCode(null);
GcpResourceNameService resourceNameService = new GcpResourceNameService();
ReflectionTestUtils.setField(resourceNameService, "maxResourceNameLength", 50);
ReflectionTestUtils.setField(builder, "resourceNameService", resourceNameService);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method isSchedulingPreemptibleTest.
@Test
public void isSchedulingPreemptibleTest() throws Exception {
// GIVEN
Group group = newGroupWithParams(ImmutableMap.of("preemptible", true));
List<CloudResource> buildableResources = builder.create(context, privateId, authenticatedContext, group, image);
context.addComputeResources(0L, buildableResources);
// WHEN
when(compute.instances()).thenReturn(instances);
when(instances.insert(anyString(), anyString(), instanceArg.capture())).thenReturn(insert);
when(insert.setPrettyPrint(anyBoolean())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(new HashMap<>());
builder.build(context, privateId, authenticatedContext, group, image, buildableResources, Collections.emptyMap());
// THEN
verify(compute).instances();
verify(instances).insert(anyString(), anyString(), instanceArg.capture());
assertTrue(instanceArg.getValue().getScheduling().getPreemptible());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method isSchedulingNotPreemptibleTest.
@Test
public void isSchedulingNotPreemptibleTest() throws Exception {
// GIVEN
Group group = newGroupWithParams(ImmutableMap.of("preemptible", false));
List<CloudResource> buildableResources = builder.create(context, privateId, authenticatedContext, group, image);
context.addComputeResources(0L, buildableResources);
// WHEN
when(compute.instances()).thenReturn(instances);
when(instances.insert(anyString(), anyString(), instanceArg.capture())).thenReturn(insert);
when(insert.setPrettyPrint(anyBoolean())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(new HashMap<>());
builder.build(context, privateId, authenticatedContext, group, image, buildableResources, Collections.emptyMap());
// THEN
verify(compute).instances();
verify(instances).insert(anyString(), anyString(), instanceArg.capture());
assertFalse(instanceArg.getValue().getScheduling().getPreemptible());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudResource in project cloudbreak by hortonworks.
the class GcpInstanceResourceBuilderTest method preemptibleParameterNotSetTest.
@Test
public void preemptibleParameterNotSetTest() throws Exception {
// GIVEN
Group group = newGroupWithParams(ImmutableMap.of());
List<CloudResource> buildableResources = builder.create(context, privateId, authenticatedContext, group, image);
context.addComputeResources(0L, buildableResources);
// WHEN
when(compute.instances()).thenReturn(instances);
when(instances.insert(anyString(), anyString(), instanceArg.capture())).thenReturn(insert);
when(insert.setPrettyPrint(anyBoolean())).thenReturn(insert);
when(insert.execute()).thenReturn(operation);
when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(new HashMap<>());
builder.build(context, privateId, authenticatedContext, group, image, buildableResources, Collections.emptyMap());
// THEN
verify(compute).instances();
verify(instances).insert(anyString(), anyString(), instanceArg.capture());
assertFalse(instanceArg.getValue().getScheduling().getPreemptible());
}
Aggregations