Search in sources :

Example 26 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class CloudConnectorExceptionTest method shouldKeepDetailedMessageWhenSingleArgConstructorCalled.

@Test
public void shouldKeepDetailedMessageWhenSingleArgConstructorCalled() {
    // GIVEN
    Throwable throwable = new IllegalArgumentException(CAUSE_MESSAGE);
    // WHEN
    CloudConnectorException cloudConnectorException = new CloudConnectorException(throwable);
    // THEN
    Assert.assertEquals("Invalid cause message", CAUSE_MESSAGE, cloudConnectorException.getCause().getMessage());
    Assert.assertEquals("Unexpected cause", throwable.getClass(), cloudConnectorException.getCause().getClass());
}
Also used : CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Test(org.junit.Test)

Example 27 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class YarnResourceConnector method check.

@Override
public List<CloudResourceStatus> check(AuthenticatedContext authenticatedContext, List<CloudResource> resources) {
    YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
    List<CloudResourceStatus> result = new ArrayList<>();
    for (CloudResource resource : resources) {
        switch(resource.getType()) {
            case YARN_APPLICATION:
                LOGGER.info("Checking Yarn application status of: {}", resource.getName());
                try {
                    ApplicationDetailRequest applicationDetailRequest = new ApplicationDetailRequest();
                    applicationDetailRequest.setName(resource.getName());
                    ResponseContext responseContext = yarnClient.getApplicationDetail(applicationDetailRequest);
                    if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_SUCCESS) {
                        ApplicationDetailResponse applicationDetailResponse = (ApplicationDetailResponse) responseContext.getResponseObject();
                        result.add(new CloudResourceStatus(resource, YarnApplicationStatus.mapResourceStatus(applicationDetailResponse.getState())));
                    } else if (responseContext.getStatusCode() == YarnResourceConstants.HTTP_NOT_FOUND) {
                        result.add(new CloudResourceStatus(resource, ResourceStatus.DELETED, "Yarn application has been killed."));
                    } else if (responseContext.getResponseError() != null) {
                        throw new CloudConnectorException(String.format("Yarn Application status check failed: HttpStatusCode: %d, Error: %s", responseContext.getStatusCode(), responseContext.getResponseError().getDiagnostics()));
                    } else {
                        throw new CloudConnectorException(String.format("Yarn Application status check failed: Invalid HttpStatusCode: %d", responseContext.getStatusCode()));
                    }
                } catch (MalformedURLException | RuntimeException e) {
                    throw new CloudConnectorException(String.format("Invalid resource exception: %s", e.getMessage()), e);
                }
                break;
            default:
                throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
        }
    }
    return result;
}
Also used : ApplicationDetailResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationDetailResponse) MalformedURLException(java.net.MalformedURLException) ApplicationDetailRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.ApplicationDetailRequest) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient)

Example 28 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class YarnResourceConnector method terminate.

@Override
public List<CloudResourceStatus> terminate(AuthenticatedContext authenticatedContext, CloudStack stack, List<CloudResource> cloudResources) {
    for (CloudResource resource : cloudResources) {
        switch(resource.getType()) {
            case YARN_APPLICATION:
                YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
                String yarnApplicationName = resource.getName();
                String stackName = authenticatedContext.getCloudContext().getName();
                LOGGER.info("Terminate stack: {}", stackName);
                try {
                    DeleteApplicationRequest deleteApplicationRequest = new DeleteApplicationRequest();
                    deleteApplicationRequest.setName(yarnApplicationName);
                    yarnClient.deleteApplication(deleteApplicationRequest);
                    LOGGER.info("Yarn Applicatin has been deleted");
                } catch (MalformedURLException | YarnClientException e) {
                    throw new CloudConnectorException("Stack cannot be deleted", e);
                }
                break;
            default:
                throw new CloudConnectorException(String.format("Invalid resource type: %s", resource.getType()));
        }
    }
    return check(authenticatedContext, cloudResources);
}
Also used : MalformedURLException(java.net.MalformedURLException) YarnClientException(com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DeleteApplicationRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.DeleteApplicationRequest) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient)

Example 29 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class YarnResourceConnector method launch.

@Override
public List<CloudResourceStatus> launch(AuthenticatedContext authenticatedContext, CloudStack stack, PersistenceNotifier persistenceNotifier, AdjustmentType adjustmentType, Long threshold) throws Exception {
    CreateApplicationRequest createApplicationRequest = new CreateApplicationRequest();
    createApplicationRequest.setName(createApplicationName(authenticatedContext));
    createApplicationRequest.setQueue(stack.getParameters().getOrDefault(YarnConstants.YARN_QUEUE_PARAMETER, defaultQueue));
    String lifeTimeStr = stack.getParameters().get(YarnConstants.YARN_LIFETIME_PARAMETER);
    createApplicationRequest.setLifetime(lifeTimeStr != null ? Integer.parseInt(lifeTimeStr) : defaultLifeTime);
    Artifact artifact = new Artifact();
    artifact.setId(stack.getImage().getImageName());
    artifact.setType("DOCKER");
    List<YarnComponent> components = new ArrayList<>();
    for (Group group : stack.getGroups()) {
        YarnComponent component = new YarnComponent();
        component.setName(group.getName());
        component.setNumberOfContainers(group.getInstancesSize());
        String userData = stack.getImage().getUserDataByType(group.getType());
        component.setLaunchCommand(String.format("/bootstrap/start-systemd '%s' '%s' '%s'", Base64.getEncoder().encodeToString(userData.getBytes()), stack.getLoginUserName(), stack.getPublicKey()));
        component.setArtifact(artifact);
        component.setDependencies(new ArrayList<>());
        InstanceTemplate instanceTemplate = group.getReferenceInstanceConfiguration().getTemplate();
        Resource resource = new Resource();
        resource.setCpus(instanceTemplate.getParameter(PlatformParametersConsts.CUSTOM_INSTANCETYPE_CPUS, Integer.class));
        resource.setMemory(instanceTemplate.getParameter(PlatformParametersConsts.CUSTOM_INSTANCETYPE_MEMORY, Integer.class));
        component.setResource(resource);
        component.setRunPrivilegedContainer(true);
        Configuration configuration = new Configuration();
        Map<String, String> propsMap = Maps.newHashMap();
        propsMap.put("conf.cb-conf.per.component", "true");
        propsMap.put("site.cb-conf.userData", '\'' + Base64.getEncoder().encodeToString(userData.getBytes()) + '\'');
        propsMap.put("site.cb-conf.sshUser", '\'' + stack.getLoginUserName() + '\'');
        propsMap.put("site.cb-conf.groupname", '\'' + group.getName() + '\'');
        propsMap.put("site.cb-conf.sshPubKey", '\'' + stack.getPublicKey() + '\'');
        configuration.setProperties(propsMap);
        ConfigFile configFileProps = new ConfigFile();
        configFileProps.setType(ConfigFileType.PROPERTIES.name());
        configFileProps.setSrcFile("cb-conf");
        configFileProps.setDestFile("/etc/cloudbreak-config.props");
        configuration.setFiles(Collections.singletonList(configFileProps));
        component.setConfiguration(configuration);
        components.add(component);
    }
    createApplicationRequest.setComponents(components);
    CloudResource yarnApplication = new Builder().type(YARN_APPLICATION).name(createApplicationRequest.getName()).build();
    persistenceNotifier.notifyAllocation(yarnApplication, authenticatedContext.getCloudContext());
    YarnClient yarnClient = yarnClientUtil.createYarnClient(authenticatedContext);
    ResponseContext responseContext = yarnClient.createApplication(createApplicationRequest);
    if (responseContext.getResponseError() != null) {
        ApplicationErrorResponse applicationErrorResponse = responseContext.getResponseError();
        throw new CloudConnectorException(String.format("Yarn Application creation error: HTTP Return: %d Error: %s", responseContext.getStatusCode(), applicationErrorResponse.getDiagnostics()));
    }
    return check(authenticatedContext, Collections.singletonList(yarnApplication));
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) Configuration(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Configuration) ConfigFile(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.ConfigFile) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) Builder(com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder) ArrayList(java.util.ArrayList) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) Resource(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Resource) ApplicationErrorResponse(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ApplicationErrorResponse) Artifact(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.Artifact) YarnClient(com.sequenceiq.cloudbreak.cloud.yarn.client.YarnClient) CreateApplicationRequest(com.sequenceiq.cloudbreak.cloud.yarn.client.model.request.CreateApplicationRequest) ResponseContext(com.sequenceiq.cloudbreak.cloud.yarn.client.model.response.ResponseContext) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) YarnComponent(com.sequenceiq.cloudbreak.cloud.yarn.client.model.core.YarnComponent) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 30 with CloudConnectorException

use of com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException in project cloudbreak by hortonworks.

the class AwsPlatformResources method accessConfigs.

@Override
public CloudAccessConfigs accessConfigs(CloudCredential cloudCredential, Region region, Map<String, String> filters) {
    String queryFailedMessage = "Could not get instance profile roles from Amazon: ";
    CloudAccessConfigs cloudAccessConfigs = new CloudAccessConfigs(new HashSet<>());
    AwsCredentialView awsCredentialView = new AwsCredentialView(cloudCredential);
    AmazonIdentityManagement client = awsClient.createAmazonIdentityManagement(awsCredentialView);
    try {
        ListInstanceProfilesResult listRolesResult = client.listInstanceProfiles();
        for (InstanceProfile instanceProfile : listRolesResult.getInstanceProfiles()) {
            Map<String, Object> properties = new HashMap<>();
            properties.put("arn", instanceProfile.getArn());
            properties.put("creationDate", instanceProfile.getCreateDate().toString());
            if (!instanceProfile.getRoles().isEmpty()) {
                String roleName = instanceProfile.getRoles().get(0).getArn();
                properties.put("roleArn", Strings.isNullOrEmpty(roleName) ? instanceProfile.getArn() : roleName);
            }
            cloudAccessConfigs.getCloudAccessConfigs().add(new CloudAccessConfig(instanceProfile.getInstanceProfileName(), instanceProfile.getInstanceProfileId(), properties));
        }
    } catch (AmazonServiceException ase) {
        if (ase.getStatusCode() == UNAUTHORIZED) {
            String policyMessage = "Could not get instance profile roles because the user does not have enough permission.";
            LOGGER.info(policyMessage + ase);
            throw new CloudConnectorException(policyMessage, ase);
        } else {
            LOGGER.error(queryFailedMessage, ase);
            throw new CloudConnectorException(queryFailedMessage + ase.getMessage(), ase);
        }
    } catch (Exception e) {
        LOGGER.error(queryFailedMessage, e);
        throw new CloudConnectorException(queryFailedMessage + e.getMessage(), e);
    }
    return cloudAccessConfigs;
}
Also used : CloudAccessConfig(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfig) HashMap(java.util.HashMap) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) CloudAccessConfigs(com.sequenceiq.cloudbreak.cloud.model.CloudAccessConfigs) AmazonServiceException(com.amazonaws.AmazonServiceException) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) IOException(java.io.IOException) AwsCredentialView(com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView) InstanceProfile(com.amazonaws.services.identitymanagement.model.InstanceProfile) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonIdentityManagement(com.amazonaws.services.identitymanagement.AmazonIdentityManagement) ListInstanceProfilesResult(com.amazonaws.services.identitymanagement.model.ListInstanceProfilesResult)

Aggregations

CloudConnectorException (com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException)64 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)14 StorageException (com.microsoft.azure.storage.StorageException)11 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)9 AzureClient (com.sequenceiq.cloudbreak.cloud.azure.client.AzureClient)9 AmazonServiceException (com.amazonaws.AmazonServiceException)8 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)8 CloudBlobContainer (com.microsoft.azure.storage.blob.CloudBlobContainer)8 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 URISyntaxException (java.net.URISyntaxException)7 ActionWentFailException (com.sequenceiq.cloudbreak.service.Retry.ActionWentFailException)6 HashMap (java.util.HashMap)6 CloudException (com.microsoft.azure.CloudException)5 CloudResourceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus)5 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)4 DescribeStacksRequest (com.amazonaws.services.cloudformation.model.DescribeStacksRequest)3 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)3 Builder (com.sequenceiq.cloudbreak.cloud.model.CloudResource.Builder)3 Group (com.sequenceiq.cloudbreak.cloud.model.Group)3