use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class GcpProvisionSetup method checkImageStatus.
@Override
public ImageStatusResult checkImageStatus(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
CloudCredential credential = authenticatedContext.getCloudCredential();
String projectId = getProjectId(credential);
String imageName = image.getImageName();
try {
Image gcpApiImage = new Image();
gcpApiImage.setName(getImageName(imageName));
Compute compute = buildCompute(credential);
Get getImages = compute.images().get(projectId, gcpApiImage.getName());
String status = getImages.execute().getStatus();
LOGGER.info("Status of image {} copy: {}", gcpApiImage.getName(), status);
if (READY.equals(status)) {
return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
}
} catch (IOException e) {
LOGGER.warn("Failed to retrieve image copy status", e);
return new ImageStatusResult(ImageStatus.CREATE_FAILED, 0);
}
return new ImageStatusResult(ImageStatus.IN_PROGRESS, ImageStatusResult.HALF);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class GcpProvisionSetup method prepareImage.
@Override
public void prepareImage(AuthenticatedContext authenticatedContext, CloudStack stack, com.sequenceiq.cloudbreak.cloud.model.Image image) {
CloudCredential credential = authenticatedContext.getCloudCredential();
CloudContext cloudContext = authenticatedContext.getCloudContext();
try {
String projectId = getProjectId(credential);
String imageName = image.getImageName();
Compute compute = buildCompute(credential);
ImageList list = compute.images().list(projectId).execute();
if (!containsSpecificImage(list, imageName)) {
Storage storage = buildStorage(credential, cloudContext.getName());
Bucket bucket = new Bucket();
bucket.setName(String.format("%s-%s-%d", projectId, cloudContext.getName(), cloudContext.getId()));
bucket.setStorageClass("STANDARD");
try {
Buckets.Insert ins = storage.buckets().insert(projectId, bucket);
ins.execute();
} catch (GoogleJsonResponseException ex) {
if (ex.getStatusCode() != HttpStatus.SC_CONFLICT) {
throw ex;
}
}
String tarName = getTarName(imageName);
Copy copy = storage.objects().copy(getBucket(imageName), tarName, bucket.getName(), tarName, new StorageObject());
copy.execute();
Image gcpApiImage = new Image();
gcpApiImage.setName(getImageName(imageName));
RawDisk rawDisk = new RawDisk();
rawDisk.setSource(String.format("http://storage.googleapis.com/%s/%s", bucket.getName(), tarName));
gcpApiImage.setRawDisk(rawDisk);
Insert ins = compute.images().insert(projectId, gcpApiImage);
ins.execute();
}
} catch (Exception e) {
Long stackId = cloudContext.getId();
String msg = String.format("Error occurred on %s stack during the setup: %s", stackId, e.getMessage());
LOGGER.error(msg, e);
throw new CloudConnectorException(msg, e);
}
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential 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.CloudCredential in project cloudbreak by hortonworks.
the class GcpMetadataCollector method getCloudVmMetaDataStatus.
private CloudVmMetaDataStatus getCloudVmMetaDataStatus(AuthenticatedContext authenticatedContext, CloudResource cloudResource, CloudInstance matchedInstance) {
CloudVmMetaDataStatus cloudVmMetaDataStatus;
if (cloudResource != null) {
CloudInstance cloudInstance = new CloudInstance(cloudResource.getName(), matchedInstance.getTemplate(), matchedInstance.getAuthentication());
try {
CloudCredential credential = authenticatedContext.getCloudCredential();
CloudContext cloudContext = authenticatedContext.getCloudContext();
Compute compute = GcpStackUtil.buildCompute(credential);
Instance executeInstance = getInstance(cloudContext, credential, compute, cloudResource.getName());
String privateIp = executeInstance.getNetworkInterfaces().get(0).getNetworkIP();
String publicIp = null;
List<AccessConfig> acl = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs();
if (acl != null && acl.get(0) != null) {
publicIp = executeInstance.getNetworkInterfaces().get(0).getAccessConfigs().get(0).getNatIP();
}
CloudInstanceMetaData metaData = new CloudInstanceMetaData(privateIp, publicIp);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, metaData);
} catch (IOException e) {
LOGGER.warn(String.format("Instance %s is not reachable", cloudResource.getName()), e);
CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.UNKNOWN);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
}
} else {
CloudVmInstanceStatus status = new CloudVmInstanceStatus(matchedInstance, InstanceStatus.TERMINATED);
cloudVmMetaDataStatus = new CloudVmMetaDataStatus(status, CloudInstanceMetaData.EMPTY_METADATA);
}
return cloudVmMetaDataStatus;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredential in project cloudbreak by hortonworks.
the class OpenStackPlatformResourcesTest method testVirtualMachines.
@Test
public void testVirtualMachines() {
CloudCredential cloudCredential = new CloudCredential(0L, "name");
OSClient osClient = mock(OSClient.class);
String regionName = "region1";
Set<String> regionsFromOpenStack = Sets.newHashSet(regionName);
List<AvailabilityZone> availabilityZones = newArrayList(new AvailabilityZone("zone1"));
Flavor flavor8GB = flavor(8192);
when(openStackClient.createOSClient(cloudCredential)).thenReturn(osClient);
when(openStackClient.getRegion(cloudCredential)).thenReturn(regionsFromOpenStack);
when(openStackClient.getZones(osClient, regionName)).thenReturn(availabilityZones);
when(openStackClient.getFlavors(osClient)).thenReturn((List) Collections.singletonList(flavor8GB));
CloudVmTypes actual = underTest.virtualMachines(cloudCredential, null, null);
Assert.assertEquals(1, actual.getCloudVmResponses().get("zone1").size());
Assert.assertEquals(1, actual.getDefaultCloudVmResponses().size());
Assert.assertEquals("8.0", actual.getCloudVmResponses().get("zone1").iterator().next().getMetaData().getProperties().get("Memory"));
Assert.assertNotNull(actual.getDefaultCloudVmResponses().get(regionName));
}
Aggregations