Search in sources :

Example 1 with GcpResourceNameService

use of com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService 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 2 with GcpResourceNameService

use of com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService in project cloudbreak by hortonworks.

the class GcpAttachedDiskResourceBuilder method create.

@Override
public List<CloudResource> create(GcpContext context, long privateId, AuthenticatedContext auth, Group group, Image image) {
    List<CloudResource> cloudResources = new ArrayList<>();
    CloudInstance instance = group.getReferenceInstanceConfiguration();
    InstanceTemplate template = instance.getTemplate();
    GcpResourceNameService resourceNameService = getResourceNameService();
    String groupName = group.getName();
    CloudContext cloudContext = auth.getCloudContext();
    String stackName = cloudContext.getName();
    for (int i = 0; i < template.getVolumes().size(); i++) {
        String resourceName = resourceNameService.resourceName(resourceType(), stackName, groupName, privateId, i);
        cloudResources.add(createNamedResource(resourceType(), resourceName));
    }
    return cloudResources;
}
Also used : CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) ArrayList(java.util.ArrayList) GcpResourceNameService(com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)2 GcpResourceNameService (com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService)2 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)2 Operation (com.google.api.services.compute.model.Operation)1 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)1 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 GcpContext (com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)1 Security (com.sequenceiq.cloudbreak.cloud.model.Security)1 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)1 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1 Matchers.anyString (org.mockito.Matchers.anyString)1