Search in sources :

Example 41 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class GcpProvisionSetup method copyImage.

public void copyImage(final String sourceBucket, final String sourceKey, final String destBucket, final String destKey, Storage storage) {
    try {
        Storage.Objects.Rewrite rewrite = storage.objects().rewrite(sourceBucket, sourceKey, destBucket, destKey, new StorageObject());
        RewriteResponse rewriteResponse = rewrite.execute();
        GcpImageAttemptMaker gcpImageAttemptMaker = gcpImageAttemptMakerFactory.create(rewriteResponse.getRewriteToken(), sourceBucket, sourceKey, destBucket, destKey, storage);
        Polling.stopAfterAttempt(ATTEMPT_COUNT).stopIfException(true).waitPeriodly(SLEEPTIME, TimeUnit.SECONDS).run(gcpImageAttemptMaker);
        LOGGER.info("Image copy has been finished successfully for {}/{}.", destBucket, destKey);
    } catch (PollerStoppedException pollerStoppedException) {
        LOGGER.error("Poller stopped for image copy: ", pollerStoppedException);
        throw new CloudbreakServiceException("Image copy failed because the copy take too long time. " + "Please check Google Cloud console because probably the image should be ready.");
    } catch (PollerException exception) {
        LOGGER.error("Polling failed for image copy: {}", sourceKey, exception);
        throw new CloudbreakServiceException("Image copy failed because: " + exception.getMessage());
    } catch (Exception e) {
        LOGGER.error("Polling could not started because: {}", e.getMessage(), e);
        throw new CloudbreakServiceException("Copying the image could not be started, " + "please check whether you have given access to CDP for storage API.");
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) IOException(java.io.IOException) TokenResponseException(com.google.api.client.auth.oauth2.TokenResponseException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) PollerException(com.dyngr.exception.PollerException) PollerStoppedException(com.dyngr.exception.PollerStoppedException) RewriteResponse(com.google.api.services.storage.model.RewriteResponse)

Example 42 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class PollerUtilTest method testWaitForWhenPollerStopExceptionHasNotCause.

@Test
public void testWaitForWhenPollerStopExceptionHasNotCause() {
    ReflectionTestUtils.setField(underTest, "pollingInterval", 1);
    ReflectionTestUtils.setField(underTest, "pollingAttempt", 1);
    CloudCredential cloudCredential = new CloudCredential(STACK_ID.toString(), "", "account");
    AuthenticatedContext ac = new AuthenticatedContext(createCloudContext(), cloudCredential);
    CloudInstance cloudInstance = new CloudInstance("instanceId", null, null, "subnet-1", "az1");
    List<CloudInstance> instances = List.of(cloudInstance);
    when(awsInstanceConnector.check(ac, instances)).thenReturn(List.of(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.FAILED)));
    PollerStoppedException actual = assertThrows(PollerStoppedException.class, () -> underTest.waitFor(ac, instances, Set.of(InstanceStatus.STARTED), ""));
    Pattern regexp = Pattern.compile("unknown operation cannot be finished in time. Duration: .*. Instances: .*");
    assertTrue(regexp.matcher(actual.getMessage()).matches());
}
Also used : Pattern(java.util.regex.Pattern) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Test(org.junit.jupiter.api.Test)

Example 43 with PollerStoppedException

use of com.dyngr.exception.PollerStoppedException in project cloudbreak by hortonworks.

the class PollerUtilTest method testWaitForWhenPollerStopExceptionHasCause.

@Test
public void testWaitForWhenPollerStopExceptionHasCause() {
    ReflectionTestUtils.setField(underTest, "pollingInterval", 1);
    ReflectionTestUtils.setField(underTest, "pollingAttempt", 1);
    CloudCredential cloudCredential = new CloudCredential(STACK_ID.toString(), "", "account");
    AuthenticatedContext ac = new AuthenticatedContext(createCloudContext(), cloudCredential);
    CloudInstance cloudInstance = new CloudInstance("instanceId", null, null, "subnet-1", "az1");
    List<CloudInstance> instances = List.of(cloudInstance);
    when(awsInstanceConnector.check(ac, instances)).thenThrow(new RuntimeException("runtime ex")).thenReturn(List.of(new CloudVmInstanceStatus(cloudInstance, InstanceStatus.FAILED)));
    PollerStoppedException actual = assertThrows(PollerStoppedException.class, () -> underTest.waitFor(ac, instances, Set.of(InstanceStatus.STARTED), ""));
    assertEquals("java.lang.RuntimeException: runtime ex", actual.getMessage());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) PollerStoppedException(com.dyngr.exception.PollerStoppedException) Test(org.junit.jupiter.api.Test)

Aggregations

PollerStoppedException (com.dyngr.exception.PollerStoppedException)43 PollerException (com.dyngr.exception.PollerException)31 UserBreakException (com.dyngr.exception.UserBreakException)30 Selectable (com.sequenceiq.cloudbreak.common.event.Selectable)28 PollingConfig (com.sequenceiq.datalake.service.sdx.PollingConfig)21 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)7 Test (org.junit.jupiter.api.Test)7 SdxCluster (com.sequenceiq.datalake.entity.SdxCluster)5 SdxCreateFailedEvent (com.sequenceiq.datalake.flow.create.event.SdxCreateFailedEvent)5 DatabaseAvailabilityType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.database.DatabaseAvailabilityType)4 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 SdxEvent (com.sequenceiq.datalake.flow.SdxEvent)4 SdxStopFailedEvent (com.sequenceiq.datalake.flow.stop.event.SdxStopFailedEvent)4 DatalakeUpgradeFailedEvent (com.sequenceiq.datalake.flow.datalake.upgrade.event.DatalakeUpgradeFailedEvent)3 SdxDiagnosticsSuccessEvent (com.sequenceiq.datalake.flow.diagnostics.event.SdxDiagnosticsSuccessEvent)3 Event (reactor.bus.Event)3 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2