Search in sources :

Example 6 with ImageStatusResult

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());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Image(com.google.api.services.compute.model.Image) Compute(com.google.api.services.compute.Compute) ImageStatusResult(com.sequenceiq.common.api.type.ImageStatusResult) Test(org.junit.jupiter.api.Test)

Example 7 with ImageStatusResult

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);
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Compute(com.google.api.services.compute.Compute) Get(com.google.api.services.compute.Compute.Images.Get) IOException(java.io.IOException) Image(com.google.api.services.compute.model.Image) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException) ImageStatusResult(com.sequenceiq.common.api.type.ImageStatusResult)

Example 8 with ImageStatusResult

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);
    }
}
Also used : CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) ImageStatusResult(com.sequenceiq.common.api.type.ImageStatusResult)

Aggregations

ImageStatusResult (com.sequenceiq.common.api.type.ImageStatusResult)8 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 Compute (com.google.api.services.compute.Compute)4 Image (com.google.api.services.compute.model.Image)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)4 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)4 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)3 Test (org.junit.jupiter.api.Test)3 CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 TokenResponseException (com.google.api.client.auth.oauth2.TokenResponseException)1 Get (com.google.api.services.compute.Compute.Images.Get)1 VirtualMachineCustomImage (com.microsoft.azure.management.compute.VirtualMachineCustomImage)1 CopyState (com.microsoft.azure.storage.blob.CopyState)1 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)1 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)1 CheckImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)1 CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)1 Location (com.sequenceiq.cloudbreak.cloud.model.Location)1 OperationException (com.sequenceiq.cloudbreak.service.OperationException)1