Search in sources :

Example 6 with CloudResource

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);
}
Also used : Addresses(com.google.api.services.compute.Compute.Addresses) NetworkInterface(com.google.api.services.compute.model.NetworkInterface) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) AccessConfig(com.google.api.services.compute.model.AccessConfig)

Example 7 with CloudResource

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);
}
Also used : PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) GcpResourceNameService(com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Matchers.anyString(org.mockito.Matchers.anyString) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Operation(com.google.api.services.compute.model.Operation) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Location(com.sequenceiq.cloudbreak.cloud.model.Location) Before(org.junit.Before)

Example 8 with CloudResource

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());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.Test)

Example 9 with CloudResource

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());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.Test)

Example 10 with CloudResource

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());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Test(org.junit.Test)

Aggregations

CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)79 ArrayList (java.util.ArrayList)33 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)29 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)20 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)17 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)16 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)13 List (java.util.List)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)8 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)8 Location (com.sequenceiq.cloudbreak.cloud.model.Location)8 Group (com.sequenceiq.cloudbreak.cloud.model.Group)7 Operation (com.google.api.services.compute.model.Operation)6 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)6 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)6 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)6 Map (java.util.Map)6 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)5