Search in sources :

Example 1 with GcpContext

use of com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext 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 GcpContext

use of com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext in project cloudbreak by hortonworks.

the class GcpCredentialConnector method verify.

@Override
public CloudCredentialStatus verify(@Nonnull AuthenticatedContext authenticatedContext) {
    Objects.requireNonNull(authenticatedContext);
    LOGGER.info("Verify credential: {}", authenticatedContext.getCloudCredential());
    GcpContext gcpContext = gcpContextBuilder.contextInit(authenticatedContext.getCloudContext(), authenticatedContext, null, null, false);
    try {
        checkGcpContextValidity(gcpContext);
        preCheckOfGooglePermission(gcpContext);
    } catch (TokenResponseException te) {
        return createFailedCloudCredentialStatusWithExc(te, authenticatedContext, getErrDescriptionFromTokenResponse(te));
    } catch (Exception e) {
        return createFailedCloudCredentialStatusWithExc(e, authenticatedContext, Optional.empty());
    }
    return new CloudCredentialStatus(authenticatedContext.getCloudCredential(), CredentialStatus.VERIFIED);
}
Also used : GcpContext(com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException) IOException(java.io.IOException) InvalidGcpContextException(com.sequenceiq.cloudbreak.cloud.gcp.context.InvalidGcpContextException) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException) CloudCredentialStatus(com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)

Aggregations

GcpContext (com.sequenceiq.cloudbreak.cloud.gcp.context.GcpContext)2 TokenResponseException (com.google.api.client.auth.oauth2.TokenResponseException)1 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 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)1 InvalidGcpContextException (com.sequenceiq.cloudbreak.cloud.gcp.context.InvalidGcpContextException)1 GcpResourceNameService (com.sequenceiq.cloudbreak.cloud.gcp.service.GcpResourceNameService)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudCredentialStatus (com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus)1 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)1 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)1 Image (com.sequenceiq.cloudbreak.cloud.model.Image)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 IOException (java.io.IOException)1 Before (org.junit.Before)1