use of com.sequenceiq.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class GcpProvisionSetupTest method testCheckImageStatusWhenImageIsStillNotReady.
@Test
public void testCheckImageStatusWhenImageIsStillNotReady() throws IOException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudStack cloudStack = mock(CloudStack.class);
Compute compute = mock(Compute.class);
Compute.Images images = mock(Compute.Images.class);
Image imageGoogle = mock(Image.class);
Compute.Images.Get imagesGet = mock(Compute.Images.Get.class);
CloudCredential cloudCredential = mock(CloudCredential.class);
com.sequenceiq.cloudbreak.cloud.model.Image image = new com.sequenceiq.cloudbreak.cloud.model.Image("super-image", Map.of(), "centos", "redhat", "http://url", "default", "1234-1234-123-123", Map.of());
when(authenticatedContext.getCloudCredential()).thenReturn(cloudCredential);
when(gcpStackUtil.getProjectId(cloudCredential)).thenReturn("project-id");
when(gcpStackUtil.getImageName(anyString())).thenReturn("super-image");
when(gcpComputeFactory.buildCompute(cloudCredential)).thenReturn(compute);
when(compute.images()).thenReturn(images);
when(images.get(anyString(), anyString())).thenReturn(imagesGet);
when(imagesGet.execute()).thenReturn(imageGoogle);
when(imageGoogle.getStatus()).thenReturn("IN_PROGRESS");
ImageStatusResult imageStatusResult = underTest.checkImageStatus(authenticatedContext, cloudStack, image);
Assert.assertEquals(ImageStatus.IN_PROGRESS, imageStatusResult.getImageStatus());
Assert.assertEquals(Integer.valueOf(50), imageStatusResult.getStatusProgressValue());
}
use of com.sequenceiq.common.api.type.ImageStatusResult 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 = gcpStackUtil.getProjectId(credential);
String imageName = image.getImageName();
try {
Image gcpApiImage = new Image();
gcpApiImage.setName(gcpStackUtil.getImageName(imageName));
Compute compute = gcpComputeFactory.buildCompute(credential);
Get getImages = compute.images().get(projectId, gcpApiImage.getName());
String status = getImages.execute().getStatus();
LOGGER.debug("Status of image {} copy: {}", gcpApiImage.getName(), status);
if (READY.equals(status)) {
return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
}
} catch (TokenResponseException e) {
gcpStackUtil.getMissingServiceAccountKeyError(e, projectId);
} catch (IOException e) {
LOGGER.info("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.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class CheckImageHandler method accept.
@Override
public void accept(Event<CheckImageRequest> event) {
LOGGER.debug("Received event: {}", event);
CheckImageRequest<CheckImageResult> request = event.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector<?> connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
Image image = request.getImage();
CloudStack stack = request.getStack();
ImageStatusResult progress = connector.setup().checkImageStatus(auth, stack, image);
CheckImageResult imageResult = new CheckImageResult(request.getResourceId(), progress.getImageStatus(), progress.getStatusProgressValue());
request.getResult().onNext(imageResult);
LOGGER.debug("Provision setup finished for {}", cloudContext);
} catch (RuntimeException e) {
CheckImageResult failure = new CheckImageResult(e, request.getResourceId(), ImageStatus.CREATE_FAILED);
request.getResult().onNext(failure);
}
}
Aggregations