Search in sources :

Example 36 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class StackCreationService method updateNodeCount.

private void updateNodeCount(Long stackId, Iterable<Group> originalGroups, Iterable<CloudResourceStatus> statuses) {
    for (Group group : originalGroups) {
        int nodeCount = group.getInstancesSize();
        List<CloudResourceStatus> failedResources = removeFailedMetadata(stackId, statuses, group);
        if (!failedResources.isEmpty()) {
            int failedCount = failedResources.size();
            InstanceGroup instanceGroup = instanceGroupRepository.findOneByGroupNameInStack(stackId, group.getName());
            instanceGroup.setNodeCount(nodeCount - failedCount);
            instanceGroupRepository.save(instanceGroup);
            flowMessageService.fireEventAndLog(stackId, Msg.STACK_INFRASTRUCTURE_ROLLBACK_MESSAGE, UPDATE_IN_PROGRESS.name(), failedCount, group.getName(), failedResources.get(0).getStatusReason());
        }
    }
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudResourceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudResourceStatus) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 37 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group 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 38 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class StackToCloudStackConverter method buildInstanceGroups.

public List<Group> buildInstanceGroups(List<InstanceGroup> instanceGroups, StackAuthentication stackAuthentication, Collection<String> deleteRequests) {
    // sort by name to avoid shuffling the different instance groups
    Collections.sort(instanceGroups);
    List<Group> groups = new ArrayList<>();
    long privateId = getFirstValidPrivateId(instanceGroups);
    for (InstanceGroup instanceGroup : instanceGroups) {
        if (instanceGroup.getTemplate() != null) {
            CloudInstance skeleton = null;
            List<CloudInstance> instances = new ArrayList<>();
            Template template = instanceGroup.getTemplate();
            int desiredNodeCount = instanceGroup.getNodeCount();
            // existing instances
            for (InstanceMetaData metaData : instanceGroup.getInstanceMetaData()) {
                InstanceStatus status = getInstanceStatus(metaData, deleteRequests);
                instances.add(buildInstance(metaData, template, stackAuthentication, instanceGroup.getGroupName(), metaData.getPrivateId(), status));
            }
            // new instances
            int existingNodesSize = instances.size();
            if (existingNodesSize < desiredNodeCount) {
                for (long i = 0; i < desiredNodeCount - existingNodesSize; i++) {
                    instances.add(buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), privateId++, InstanceStatus.CREATE_REQUESTED));
                }
            }
            if (existingNodesSize == desiredNodeCount && desiredNodeCount == 0) {
                skeleton = buildInstance(null, template, stackAuthentication, instanceGroup.getGroupName(), 0L, InstanceStatus.CREATE_REQUESTED);
            }
            Json attributes = instanceGroup.getAttributes();
            InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stackAuthentication);
            Map<String, Object> fields = attributes == null ? Collections.emptyMap() : attributes.getMap();
            groups.add(new Group(instanceGroup.getGroupName(), instanceGroup.getInstanceGroupType(), instances, buildSecurity(instanceGroup), skeleton, fields, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
        }
    }
    return groups;
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Json(com.sequenceiq.cloudbreak.domain.json.Json) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)

Example 39 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class StackToCloudStackConverter method buildInstances.

public List<CloudInstance> buildInstances(Stack stack) {
    List<Group> groups = buildInstanceGroups(stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), Collections.emptySet());
    List<CloudInstance> cloudInstances = new ArrayList<>();
    for (Group group : groups) {
        cloudInstances.addAll(group.getInstances());
    }
    return cloudInstances;
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance)

Example 40 with Group

use of com.sequenceiq.cloudbreak.cloud.model.Group in project cloudbreak by hortonworks.

the class InstanceMetadataService method saveInstanceRequests.

public void saveInstanceRequests(Stack stack, Iterable<Group> groups) {
    Set<InstanceGroup> instanceGroups = stack.getInstanceGroups();
    for (Group group : groups) {
        InstanceGroup instanceGroup = getInstanceGroup(instanceGroups, group.getName());
        List<InstanceMetaData> existingInGroup = instanceMetaDataRepository.findAllByInstanceGroupAndInstanceStatus(instanceGroup, com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
        for (CloudInstance cloudInstance : group.getInstances()) {
            InstanceTemplate instanceTemplate = cloudInstance.getTemplate();
            boolean exists = existingInGroup.stream().anyMatch(i -> i.getPrivateId().equals(instanceTemplate.getPrivateId()));
            if (InstanceStatus.CREATE_REQUESTED == instanceTemplate.getStatus() && !exists) {
                InstanceMetaData instanceMetaData = new InstanceMetaData();
                instanceMetaData.setPrivateId(instanceTemplate.getPrivateId());
                instanceMetaData.setInstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus.REQUESTED);
                instanceMetaData.setInstanceGroup(instanceGroup);
                instanceMetaDataRepository.save(instanceMetaData);
            }
        }
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Aggregations

Group (com.sequenceiq.cloudbreak.cloud.model.Group)62 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)37 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)36 Test (org.junit.Test)36 Network (com.sequenceiq.cloudbreak.cloud.model.Network)35 HashMap (java.util.HashMap)35 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)33 Subnet (com.sequenceiq.cloudbreak.cloud.model.Subnet)33 Matchers.containsString (org.hamcrest.Matchers.containsString)20 AzureCredentialView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureCredentialView)17 AzureStackView (com.sequenceiq.cloudbreak.cloud.azure.view.AzureStackView)17 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)15 DescribeSubnetsResult (com.amazonaws.services.ec2.model.DescribeSubnetsResult)15 Vpc (com.amazonaws.services.ec2.model.Vpc)15 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)15 DescribeVpcsResult (com.amazonaws.services.ec2.model.DescribeVpcsResult)14 Location (com.sequenceiq.cloudbreak.cloud.model.Location)14 ArrayList (java.util.ArrayList)14 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)11 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)9