Search in sources :

Example 6 with Template

use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.

the class TemplateController method getPublic.

@Override
public TemplateResponse getPublic(@PathVariable String name) {
    IdentityUser user = authenticatedUserService.getCbUser();
    Template template = templateService.getPublicTemplate(name, user);
    return convert(template);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 7 with Template

use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.

the class TemplateController method getPublics.

@Override
public Set<TemplateResponse> getPublics() {
    IdentityUser user = authenticatedUserService.getCbUser();
    Set<Template> templates = templateService.retrieveAccountTemplates(user);
    return convert(templates);
}
Also used : IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) Template(com.sequenceiq.cloudbreak.domain.Template)

Example 8 with Template

use of com.sequenceiq.cloudbreak.domain.Template 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 9 with Template

use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.

the class ServiceTestUtils method createTemplate.

public static Template createTemplate(String owner, String account, String platform) {
    switch(platform) {
        case AWS:
            Template awsTemplate = new Template();
            awsTemplate.setId(1L);
            awsTemplate.setOwner(owner);
            awsTemplate.setAccount(account);
            awsTemplate.setInstanceType(C3LARGE_INSTANCE);
            awsTemplate.setVolumeType("gp2");
            awsTemplate.setVolumeCount(1);
            awsTemplate.setVolumeSize(100);
            awsTemplate.setDescription("aws test template");
            awsTemplate.setPublicInAccount(true);
            awsTemplate.setCloudPlatform(AWS);
            return awsTemplate;
        case GCP:
            Template gcpTemplate = new Template();
            gcpTemplate.setId(1L);
            gcpTemplate.setInstanceType(N1_STANDARD_1);
            gcpTemplate.setVolumeType("pd-standard");
            gcpTemplate.setDescription("gcp test template");
            gcpTemplate.setOwner(owner);
            gcpTemplate.setAccount(account);
            gcpTemplate.setVolumeCount(1);
            gcpTemplate.setVolumeSize(100);
            gcpTemplate.setPublicInAccount(true);
            gcpTemplate.setCloudPlatform(GCP);
            return gcpTemplate;
        default:
            return null;
    }
}
Also used : Template(com.sequenceiq.cloudbreak.domain.Template)

Example 10 with Template

use of com.sequenceiq.cloudbreak.domain.Template in project cloudbreak by hortonworks.

the class ServiceTestUtils method createStack.

public static Stack createStack(String owner, String account, Template template, Credential credential, Cluster cluster, Set<Resource> resources) {
    Template template1 = createTemplate(AWS);
    Template template2 = createTemplate(AWS);
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    InstanceGroup instanceGroup1 = new InstanceGroup();
    instanceGroup1.setNodeCount(2);
    instanceGroup1.setGroupName("master");
    instanceGroup1.setTemplate(template1);
    instanceGroups.add(instanceGroup1);
    InstanceGroup instanceGroup2 = new InstanceGroup();
    instanceGroup2.setNodeCount(2);
    instanceGroup2.setGroupName("slave_1");
    instanceGroup2.setTemplate(template2);
    instanceGroups.add(instanceGroup2);
    Stack stack = new Stack();
    stack.setCredential(credential);
    stack.setRegion("EU_WEST_1");
    stack.setOwner(owner);
    stack.setAccount(account);
    stack.setStackStatus(new StackStatus(stack, Status.REQUESTED, "", DetailedStackStatus.PROVISION_REQUESTED));
    stack.setInstanceGroups(instanceGroups);
    stack.setCluster(cluster);
    stack.setPublicInAccount(true);
    stack.setResources(resources);
    return stack;
}
Also used : DetailedStackStatus(com.sequenceiq.cloudbreak.api.model.DetailedStackStatus) StackStatus(com.sequenceiq.cloudbreak.domain.StackStatus) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Aggregations

Template (com.sequenceiq.cloudbreak.domain.Template)25 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)6 IdentityUser (com.sequenceiq.cloudbreak.common.model.user.IdentityUser)5 NotFoundException (com.sequenceiq.cloudbreak.controller.NotFoundException)5 Credential (com.sequenceiq.cloudbreak.domain.Credential)4 CloudVmTypes (com.sequenceiq.cloudbreak.cloud.model.CloudVmTypes)3 Json (com.sequenceiq.cloudbreak.domain.json.Json)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)2 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)2 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)2 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)2 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)2 Platform (com.sequenceiq.cloudbreak.cloud.model.Platform)2 PlatformDisks (com.sequenceiq.cloudbreak.cloud.model.PlatformDisks)2 VmTypeMeta (com.sequenceiq.cloudbreak.cloud.model.VmTypeMeta)2 VolumeParameterConfig (com.sequenceiq.cloudbreak.cloud.model.VolumeParameterConfig)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 SecurityGroup (com.sequenceiq.cloudbreak.domain.SecurityGroup)2