Search in sources :

Example 61 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class CheckImageAction method doExecute.

@Override
protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
    CheckImageResult checkImageResult = stackCreationService.checkImage(context);
    switch(checkImageResult.getImageStatus()) {
        case IN_PROGRESS:
            repeat(context);
            break;
        case CREATE_FINISHED:
            sendEvent(context);
            break;
        case CREATE_FAILED:
            LOGGER.info("Error during image status check: {}", payload);
            int faultNum = getFaultNum(variables) + 1;
            if (faultNum == FAULT_TOLERANCE) {
                removeFaultNum(variables);
                throw new CloudbreakServiceException("Image copy failed.");
            } else {
                setFaultNum(variables, faultNum);
                repeat(context);
            }
            break;
        default:
            LOGGER.error("Unknown image status: {}", checkImageResult.getImageStatus());
            break;
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)

Example 62 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class GrpcUmsClientTest method testHasRightsUsesCheckRightWhenRequestNumberIsLessThenThreshold.

@Test
public void testHasRightsUsesCheckRightWhenRequestNumberIsLessThenThreshold() {
    String resourceCrn1 = CrnTestUtil.getDatahubCrnBuilder().setAccountId("a1").setResource("r1").build().toString();
    String resourceCrn2 = CrnTestUtil.getDatahubCrnBuilder().setAccountId("a1").setResource("r2").build().toString();
    doNothing().when(authorizationClient).checkRight(REQUEST_ID.get(), USER_CRN, "right", resourceCrn1);
    doThrow(new RuntimeException("Permission denied")).when(authorizationClient).checkRight(REQUEST_ID.get(), USER_CRN, "right", resourceCrn2);
    CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> {
        underTest.hasRights(USER_CRN, List.of(resourceCrn1, resourceCrn2), "right", REQUEST_ID, regionAwareInternalCrnGeneratorFactory);
    });
    assertEquals("Authorization failed due to user management service call failed with error.", exception.getMessage());
    InOrder inOrder = inOrder(authorizationClient);
    inOrder.verify(authorizationClient).checkRight(REQUEST_ID.get(), USER_CRN, "right", resourceCrn1);
    inOrder.verify(authorizationClient).checkRight(REQUEST_ID.get(), USER_CRN, "right", resourceCrn2);
}
Also used : InOrder(org.mockito.InOrder) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 63 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class SecretAspects method proceedDelete.

private Object proceedDelete(ProceedingJoinPoint proceedingJoinPoint) {
    Collection<Object> entities = convertFirstArgToCollection(proceedingJoinPoint);
    for (Object entity : entities) {
        try {
            for (Field field : entity.getClass().getDeclaredFields()) {
                if (field.isAnnotationPresent(SecretValue.class)) {
                    LOGGER.debug("Found SecretValue annotation on {}", field);
                    field.setAccessible(true);
                    Secret path = (Secret) field.get(entity);
                    if (path != null && path.getSecret() != null) {
                        secretService.delete(path.getSecret());
                        LOGGER.debug("Secret deleted at path: {}", path);
                    } else {
                        LOGGER.debug("Secret is null for field: {}.{}", field.getDeclaringClass(), field.getName());
                    }
                }
            }
        } catch (IllegalArgumentException e) {
            LOGGER.error("Given entity isn't instance of TenantAwareResource or AccountIdAwareResource. Secret is not deleted!", e);
            throw new CloudbreakServiceException(e);
        } catch (Exception e) {
            LOGGER.warn("Looks like something went wrong with Secret store. Secret is not deleted!", e);
            throw new CloudbreakServiceException(e);
        }
    }
    Object proceed;
    try {
        proceed = proceedingJoinPoint.proceed();
    } catch (RuntimeException re) {
        LOGGER.warn("Failed to invoke repository delete", re);
        throw re;
    } catch (Throwable throwable) {
        LOGGER.error("Failed to invoke repository delete", throwable);
        throw new CloudbreakServiceException(throwable);
    }
    return proceed;
}
Also used : Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) Field(java.lang.reflect.Field) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 64 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ClouderaManagerSetupServiceTest method testRefreshParcelReposWhenApiExceptionOccursShouldThrowCloudbreakServiceException.

@Test
public void testRefreshParcelReposWhenApiExceptionOccursShouldThrowCloudbreakServiceException() {
    ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
    when(clouderaManagerRepo.getPredefined()).thenReturn(true);
    when(clusterComponentProvider.getClouderaManagerRepoDetails(anyLong())).thenReturn(clouderaManagerRepo);
    doThrow(new ClouderaManagerOperationFailedException("error")).when(clouderaManagerApiFactory).getClouderaManagerResourceApi(any(ApiClient.class));
    CloudbreakServiceException actual = assertThrows(CloudbreakServiceException.class, () -> underTest.refreshParcelRepos());
    assertEquals(CloudbreakServiceException.class, actual.getClass());
}
Also used : ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ApiClient(com.cloudera.api.swagger.client.ApiClient) Test(org.junit.jupiter.api.Test)

Example 65 with CloudbreakServiceException

use of com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException in project cloudbreak by hortonworks.

the class ClusterTemplateViewToClusterTemplateViewV4ResponseConverter method convert.

public ClusterTemplateViewV4Response convert(ClusterTemplateView source) {
    ClusterTemplateViewV4Response clusterTemplateViewV4Response = new ClusterTemplateViewV4Response();
    clusterTemplateViewV4Response.setName(source.getName());
    clusterTemplateViewV4Response.setDescription(source.getDescription());
    clusterTemplateViewV4Response.setCrn(source.getResourceCrn());
    clusterTemplateViewV4Response.setCloudPlatform(source.getCloudPlatform());
    clusterTemplateViewV4Response.setStatus(source.getStatus());
    clusterTemplateViewV4Response.setId(source.getId());
    clusterTemplateViewV4Response.setDatalakeRequired(source.getDatalakeRequired());
    clusterTemplateViewV4Response.setStatus(source.getStatus());
    clusterTemplateViewV4Response.setType(source.getType());
    clusterTemplateViewV4Response.setFeatureState(source.getFeatureState());
    if (source.getStackTemplate() != null) {
        ClusterTemplateStackApiView stackTemplate = source.getStackTemplate();
        clusterTemplateViewV4Response.setNodeCount(getFullNodeCount(stackTemplate));
        if (stackTemplate.getCluster() != null) {
            ClusterTemplateClusterApiView cluster = stackTemplate.getCluster();
            clusterTemplateViewV4Response.setStackType(cluster.getBlueprint() != null ? cluster.getBlueprint().getStackType() : "");
            clusterTemplateViewV4Response.setStackVersion(cluster.getBlueprint() != null ? cluster.getBlueprint().getStackVersion() : "");
        }
        if (stackTemplate.getEnvironmentCrn() != null) {
            clusterTemplateViewV4Response.setEnvironmentCrn(stackTemplate.getEnvironmentCrn());
        }
    } else if (source.getStatus().isDefault()) {
        try {
            DistroXV1Request distroXV1Request = new Json(getTemplateString(source.getTemplateContent())).get(DefaultClusterTemplateV4Request.class).getDistroXTemplate();
            clusterTemplateViewV4Response.setNodeCount(getFullNodeCount(distroXV1Request));
            clusterTemplateViewV4Response.setStackType("CDH");
            clusterTemplateViewV4Response.setStackVersion(source.getClouderaRuntimeVersion());
        } catch (IOException e) {
            LOGGER.error("CDP was not able to convert back {} template: {}", source.getName(), e.getMessage());
            throw new CloudbreakServiceException("CDP was not able to give back your template: ", e);
        }
    }
    clusterTemplateViewV4Response.setCreated(source.getCreated());
    return clusterTemplateViewV4Response;
}
Also used : ClusterTemplateStackApiView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateStackApiView) ClusterTemplateClusterApiView(com.sequenceiq.cloudbreak.domain.view.ClusterTemplateClusterApiView) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) ClusterTemplateViewV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.clustertemplate.responses.ClusterTemplateViewV4Response) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)

Aggregations

CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)142 Test (org.junit.jupiter.api.Test)25 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)24 List (java.util.List)20 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)18 IOException (java.io.IOException)18 Map (java.util.Map)18 ApiException (com.cloudera.api.swagger.client.ApiException)17 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)16 Collectors (java.util.stream.Collectors)15 Inject (javax.inject.Inject)15 Logger (org.slf4j.Logger)15 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)14 LoggerFactory (org.slf4j.LoggerFactory)14 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)13 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)12 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)12 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)12 Optional (java.util.Optional)12 Set (java.util.Set)12