Search in sources :

Example 11 with InstanceTemplate

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

the class OpenStackInstanceBuilder method build.

@Override
public List<CloudResource> build(OpenStackContext context, long privateId, AuthenticatedContext auth, Group group, Image image, List<CloudResource> buildableResource, Map<String, String> tags) {
    CloudResource resource = buildableResource.get(0);
    try {
        OSClient<?> osClient = createOSClient(auth);
        InstanceTemplate template = getInstanceTemplate(group, privateId);
        CloudResource port = getPort(context.getComputeResources(privateId));
        KeystoneCredentialView osCredential = new KeystoneCredentialView(auth);
        NovaInstanceView novaInstanceView = new NovaInstanceView(context.getName(), template, group.getType(), group.getLoginUserName());
        String imageId = osClient.imagesV2().list(Collections.singletonMap("name", image.getImageName())).get(0).getId();
        LOGGER.info("Selected image id: {}", imageId);
        Map<String, String> metadata = mergeMetadata(novaInstanceView.getMetadataMap(), tags);
        ServerCreateBuilder serverCreateBuilder = Builders.server().name(resource.getName()).image(imageId).flavor(getFlavorId(osClient, novaInstanceView.getFlavor())).keypairName(osCredential.getKeyPairName()).addMetadata(metadata).addNetworkPort(port.getStringParameter(OpenStackConstants.PORT_ID)).userData(new String(Base64.encodeBase64(image.getUserDataByType(group.getType()).getBytes())));
        BlockDeviceMappingBuilder blockDeviceMappingBuilder = Builders.blockDeviceMapping().uuid(imageId).sourceType(BDMSourceType.IMAGE).deviceName("/dev/vda").bootIndex(0).deleteOnTermination(true).destinationType(BDMDestType.LOCAL);
        serverCreateBuilder = serverCreateBuilder.blockDevice(blockDeviceMappingBuilder.build());
        for (CloudResource computeResource : context.getComputeResources(privateId)) {
            if (computeResource.getType() == ResourceType.OPENSTACK_ATTACHED_DISK) {
                BlockDeviceMappingCreate blockDeviceMappingCreate = Builders.blockDeviceMapping().uuid(computeResource.getReference()).deviceName(computeResource.getStringParameter(OpenStackConstants.VOLUME_MOUNT_POINT)).sourceType(BDMSourceType.VOLUME).destinationType(BDMDestType.VOLUME).build();
                serverCreateBuilder.blockDevice(blockDeviceMappingCreate);
            }
        }
        ServerCreate serverCreate = serverCreateBuilder.build();
        Server server = osClient.compute().servers().boot(serverCreate);
        return Collections.singletonList(createPersistedResource(resource, group.getName(), server.getId(), Collections.singletonMap(OpenStackConstants.SERVER, server)));
    } catch (OS4JException ex) {
        LOGGER.error("Failed to create OpenStack instance with privateId: {}", privateId, ex);
        throw new OpenStackResourceException("Instance creation failed", resourceType(), resource.getName(), ex);
    }
}
Also used : Server(org.openstack4j.model.compute.Server) ServerCreate(org.openstack4j.model.compute.ServerCreate) BlockDeviceMappingCreate(org.openstack4j.model.compute.BlockDeviceMappingCreate) BlockDeviceMappingBuilder(org.openstack4j.model.compute.builder.BlockDeviceMappingBuilder) OS4JException(org.openstack4j.api.exceptions.OS4JException) NovaInstanceView(com.sequenceiq.cloudbreak.cloud.openstack.view.NovaInstanceView) ServerCreateBuilder(org.openstack4j.model.compute.builder.ServerCreateBuilder) OpenStackResourceException(com.sequenceiq.cloudbreak.cloud.openstack.nativ.OpenStackResourceException) KeystoneCredentialView(com.sequenceiq.cloudbreak.cloud.openstack.view.KeystoneCredentialView) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 12 with InstanceTemplate

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

the class OpenStackFlavorVerifierTest method createGroup.

private Group createGroup(String flavor) {
    InstanceTemplate template = new InstanceTemplate(flavor, null, null, new ArrayList<>(), null, null, null);
    CloudInstance skeleton = new CloudInstance("id1", template, null);
    Group group = new Group("name", InstanceGroupType.GATEWAY, new ArrayList<>(), null, skeleton, null, "loginUserName", "publicKey");
    return group;
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 13 with InstanceTemplate

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

the class OpenStackNativeMetaDataCollector method collect.

@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
    List<InstanceTemplate> templates = Lists.transform(vms, CloudInstance::getTemplate);
    Map<String, InstanceTemplate> templateMap = Maps.uniqueIndex(templates, from -> utils.getPrivateInstanceId(from.getGroupName(), Long.toString(from.getPrivateId())));
    OSClient<?> client = openStackClient.createOSClient(authenticatedContext);
    List<CloudVmMetaDataStatus> results = new ArrayList<>();
    for (CloudResource resource : resources) {
        if (resource.getType() == ResourceType.OPENSTACK_INSTANCE) {
            String instanceUUID = resource.getReference();
            Server server = client.compute().servers().get(instanceUUID);
            if (server != null) {
                Map<String, String> metadata = server.getMetadata();
                String privateInstanceId = utils.getPrivateInstanceId(metadata);
                InstanceTemplate template = templateMap.get(privateInstanceId);
                if (template != null) {
                    CloudInstanceMetaData md = cloudInstanceMetaDataExtractor.extractMetadata(client, server, instanceUUID);
                    // TODO use here sshkey
                    CloudInstance cloudInstance = new CloudInstance(instanceUUID, template, null);
                    CloudVmInstanceStatus status = new CloudVmInstanceStatus(cloudInstance, InstanceStatus.CREATED);
                    results.add(new CloudVmMetaDataStatus(status, md));
                }
            }
        }
    }
    return results;
}
Also used : Server(org.openstack4j.model.compute.Server) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudResource(com.sequenceiq.cloudbreak.cloud.model.CloudResource) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 14 with InstanceTemplate

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

the class ParameterGenerator method createCloudStack.

public CloudStack createCloudStack() {
    List<Group> groups = new ArrayList<>();
    String name = "master";
    List<Volume> volumes = Arrays.asList(new Volume("/hadoop/fs1", "HDD", 1), new Volume("/hadoop/fs2", "HDD", 1));
    InstanceTemplate instanceTemplate = new InstanceTemplate("m1.medium", name, 0L, volumes, InstanceStatus.CREATE_REQUESTED, new HashMap<>(), 0L);
    InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
    CloudInstance instance = new CloudInstance("SOME_ID", instanceTemplate, instanceAuthentication);
    List<SecurityRule> rules = Collections.singletonList(new SecurityRule("0.0.0.0/0", new PortDefinition[] { new PortDefinition("22", "22"), new PortDefinition("443", "443") }, "tcp"));
    Security security = new Security(rules, null);
    groups.add(new Group(name, InstanceGroupType.CORE, Collections.singletonList(instance), security, null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey()));
    Map<InstanceGroupType, String> userData = ImmutableMap.of(InstanceGroupType.CORE, "CORE", InstanceGroupType.GATEWAY, "GATEWAY");
    Image image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "", "default", "default-id");
    Subnet subnet = new Subnet("10.0.0.0/24");
    Network network = new Network(subnet);
    network.putParameter("publicNetId", "028ffc0c-63c5-4ca0-802a-3ac753eaf76c");
    return new CloudStack(groups, network, image, new HashMap<>(), new HashMap<>(), null, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) ArrayList(java.util.ArrayList) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) Network(com.sequenceiq.cloudbreak.cloud.model.Network) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)

Example 15 with InstanceTemplate

use of com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate 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)

Aggregations

InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)31 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)25 ArrayList (java.util.ArrayList)17 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)16 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)13 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)11 CloudResource (com.sequenceiq.cloudbreak.cloud.model.CloudResource)9 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)8 Group (com.sequenceiq.cloudbreak.cloud.model.Group)8 HashMap (java.util.HashMap)7 AwsCredentialView (com.sequenceiq.cloudbreak.cloud.aws.view.AwsCredentialView)6 AmazonAutoScalingClient (com.amazonaws.services.autoscaling.AmazonAutoScalingClient)5 AmazonCloudFormationClient (com.amazonaws.services.cloudformation.AmazonCloudFormationClient)5 CreateTagsRequest (com.amazonaws.services.ec2.model.CreateTagsRequest)5 Instance (com.amazonaws.services.ec2.model.Instance)5 Reservation (com.amazonaws.services.ec2.model.Reservation)5 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)5 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)5 Test (org.junit.Test)5 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)4