use of com.sequenceiq.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class ServiceProviderSetupAdapter method checkImage.
public ImageStatusResult checkImage(Stack stack) throws Exception {
Location location = location(region(stack.getRegion()), availabilityZone(stack.getAvailabilityZone()));
CloudContext cloudContext = CloudContext.Builder.builder().withId(stack.getId()).withName(stack.getName()).withCrn(stack.getResourceCrn()).withPlatform(stack.getCloudPlatform()).withVariant(stack.getPlatformVariant()).withLocation(location).withWorkspaceId(stack.getWorkspace().getId()).withAccountId(stack.getTenant().getId()).build();
CloudCredential cloudCredential = stackUtil.getCloudCredential(stack);
Image image = imageService.getImage(stack.getId());
CheckImageRequest<CheckImageResult> checkImageRequest = new CheckImageRequest<>(cloudContext, cloudCredential, cloudStackConverter.convert(stack), image);
LOGGER.debug("Triggering event: {}", checkImageRequest);
eventBus.notify(checkImageRequest.selector(), eventFactory.createEvent(checkImageRequest));
try {
CheckImageResult res = checkImageRequest.await();
LOGGER.debug("Result: {}", res);
if (res.getErrorDetails() != null) {
LOGGER.info("Failed to check image state", res.getErrorDetails());
throw new OperationException(res.getErrorDetails());
}
return new ImageStatusResult(res.getImageStatus(), res.getStatusProgressValue());
} catch (InterruptedException e) {
LOGGER.info("Error while executing check image", e);
throw new OperationException(e);
}
}
use of com.sequenceiq.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class AzureImageSetupService method getImageStatusResult.
private ImageStatusResult getImageStatusResult(String imageResourceGroupName, AzureClient client, AzureImageInfo azureImageInfo, String imageStorageName) {
CopyState copyState = client.getCopyStatus(imageResourceGroupName, imageStorageName, IMAGES_CONTAINER, azureImageInfo.getImageName());
boolean storageContainsImage = storageContainsImage(client, imageResourceGroupName, imageStorageName, azureImageInfo.getImageName());
if (copyState == null && storageContainsImage) {
LOGGER.debug("The copy has been finished because the storage account already contains the image.");
return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
} else if (copyState == null && !storageContainsImage) {
throw new CloudConnectorException("Image copy failed because the copy state is not available and the storage account does not contains the image.");
}
if (CopyStatus.SUCCESS.equals(copyState.getStatus())) {
if (!storageContainsImage) {
LOGGER.error("The image has not been found in the storage account.");
return new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.COMPLETED);
}
LOGGER.info("The image copy has been finished.");
return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
} else if (isCopyStatusFailed(copyState)) {
LOGGER.error("The image copy has failed with status: {}", copyState.getStatus());
return new ImageStatusResult(ImageStatus.CREATE_FAILED, 0);
} else {
int percentage = (int) (((double) copyState.getBytesCopied() * ImageStatusResult.COMPLETED) / copyState.getTotalBytes());
LOGGER.info("CopyStatus, Total:{} / Pending:{} bytes, {}%", copyState.getTotalBytes(), copyState.getBytesCopied(), percentage);
return new ImageStatusResult(ImageStatus.IN_PROGRESS, percentage);
}
}
use of com.sequenceiq.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class AzureImageSetupService method checkImageStatus.
public ImageStatusResult checkImageStatus(AuthenticatedContext ac, CloudStack stack, Image image) {
if (azureImageFormatValidator.isMarketplaceImageFormat(image)) {
LOGGER.info("Skipping image copy check as target image ({}) is an Azure Marketplace image!", image.getImageName());
return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
}
CloudContext cloudContext = ac.getCloudContext();
String imageResourceGroupName = azureResourceGroupMetadataProvider.getImageResourceGroupName(cloudContext, stack);
AzureClient client = ac.getParameter(AzureClient.class);
AzureImageInfo azureImageInfo = azureImageInfoService.getImageInfo(imageResourceGroupName, image.getImageName(), ac, client);
Optional<VirtualMachineCustomImage> customImage = azureManagedImageService.findVirtualMachineCustomImage(azureImageInfo, client);
if (customImage.isPresent()) {
LOGGER.info("Custom image with id {} already exists in the target resource group {}, bypassing VHD copy check!", customImage.get().id(), imageResourceGroupName);
return new ImageStatusResult(ImageStatus.CREATE_FINISHED, ImageStatusResult.COMPLETED);
}
AzureCredentialView acv = new AzureCredentialView(ac.getCloudCredential());
String imageStorageName = armStorage.getImageStorageName(acv, cloudContext, stack);
try {
return getImageStatusResult(imageResourceGroupName, client, azureImageInfo, imageStorageName);
} catch (RuntimeException ex) {
String msg = String.format("Failed to check the status of the image in resource group '%s', image storage name '%s'", imageResourceGroupName, imageStorageName);
LOGGER.error(msg, ex);
return new ImageStatusResult(ImageStatus.CREATE_FAILED, ImageStatusResult.INIT);
}
}
use of com.sequenceiq.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class GcpProvisionSetupTest method testCheckImageStatusWhenImageIsReady.
@Test
public void testCheckImageStatusWhenImageIsReady() 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("READY");
ImageStatusResult imageStatusResult = underTest.checkImageStatus(authenticatedContext, cloudStack, image);
Assert.assertEquals(ImageStatus.CREATE_FINISHED, imageStatusResult.getImageStatus());
Assert.assertEquals(Integer.valueOf(100), imageStatusResult.getStatusProgressValue());
}
use of com.sequenceiq.common.api.type.ImageStatusResult in project cloudbreak by hortonworks.
the class GcpProvisionSetupTest method testCheckImageStatusWhenImageIsDropIOExceptionShouldCreateFailed.
@Test
public void testCheckImageStatusWhenImageIsDropIOExceptionShouldCreateFailed() throws IOException {
AuthenticatedContext authenticatedContext = mock(AuthenticatedContext.class);
CloudStack cloudStack = mock(CloudStack.class);
Compute compute = mock(Compute.class);
Compute.Images images = mock(Compute.Images.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()).thenThrow(IOException.class);
ImageStatusResult imageStatusResult = underTest.checkImageStatus(authenticatedContext, cloudStack, image);
Assert.assertEquals(ImageStatus.CREATE_FAILED, imageStatusResult.getImageStatus());
Assert.assertEquals(Integer.valueOf(0), imageStatusResult.getStatusProgressValue());
}
Aggregations