Search in sources :

Example 16 with Image

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

the class StackToCloudStackConverter method convert.

public CloudStack convert(Stack stack, Collection<String> deleteRequestedInstances) {
    Image image = null;
    List<Group> instanceGroups = buildInstanceGroups(stack.getInstanceGroupsAsList(), stack.getStackAuthentication(), deleteRequestedInstances);
    try {
        image = imageService.getImage(stack.getId());
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info(e.getMessage());
    }
    Network network = buildNetwork(stack);
    StackTemplate stackTemplate = componentConfigProvider.getStackTemplate(stack.getId());
    InstanceAuthentication instanceAuthentication = buildInstanceAuthentication(stack.getStackAuthentication());
    String template = null;
    if (stackTemplate != null) {
        template = stackTemplate.getTemplate();
    }
    return new CloudStack(instanceGroups, network, image, stack.getParameters(), getUserDefinedTags(stack), template, instanceAuthentication, instanceAuthentication.getLoginUserName(), instanceAuthentication.getPublicKey());
}
Also used : InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) Network(com.sequenceiq.cloudbreak.cloud.model.Network) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack)

Example 17 with Image

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

the class HeatTemplateBuilderTest method setup.

@Before
public void setup() throws IOException, TemplateException {
    initMocks(this);
    FreeMarkerConfigurationFactoryBean factoryBean = new FreeMarkerConfigurationFactoryBean();
    factoryBean.setPreferFileSystemAccess(false);
    factoryBean.setTemplateLoaderPath("classpath:/");
    factoryBean.afterPropertiesSet();
    Configuration configuration = factoryBean.getObject();
    ReflectionTestUtils.setField(heatTemplateBuilder, "freemarkerConfiguration", configuration);
    ReflectionTestUtils.setField(heatTemplateBuilder, "openStackHeatTemplatePath", templatePath);
    stackName = "testStack";
    groups = new ArrayList<>(1);
    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");
    Map<String, String> tags = new HashMap<>();
    tags.put(CloudbreakResourceType.DISK.templateVariable(), CloudbreakResourceType.DISK.key());
    tags.put(CloudbreakResourceType.INSTANCE.templateVariable(), CloudbreakResourceType.INSTANCE.key());
    tags.put(CloudbreakResourceType.IP.templateVariable(), CloudbreakResourceType.IP.key());
    tags.put(CloudbreakResourceType.NETWORK.templateVariable(), CloudbreakResourceType.NETWORK.key());
    tags.put(CloudbreakResourceType.SECURITY.templateVariable(), CloudbreakResourceType.SECURITY.key());
    tags.put(CloudbreakResourceType.STORAGE.templateVariable(), CloudbreakResourceType.STORAGE.key());
    tags.put(CloudbreakResourceType.TEMPLATE.templateVariable(), CloudbreakResourceType.TEMPLATE.key());
    when(defaultCostTaggingService.prepareInstanceTagging()).thenReturn(tags);
    image = new Image("cb-centos66-amb200-2015-05-25", userData, "redhat6", "url", "default", null);
}
Also used : Group(com.sequenceiq.cloudbreak.cloud.model.Group) InstanceAuthentication(com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication) PortDefinition(com.sequenceiq.cloudbreak.cloud.model.PortDefinition) FreeMarkerConfigurationFactoryBean(org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean) Configuration(freemarker.template.Configuration) InstanceGroupType(com.sequenceiq.cloudbreak.api.model.InstanceGroupType) HashMap(java.util.HashMap) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) Matchers.containsString(org.hamcrest.Matchers.containsString) SecurityRule(com.sequenceiq.cloudbreak.cloud.model.SecurityRule) Security(com.sequenceiq.cloudbreak.cloud.model.Security) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Volume(com.sequenceiq.cloudbreak.cloud.model.Volume) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) Before(org.junit.Before)

Example 18 with Image

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

the class CheckImageHandler method accept.

@Override
public void accept(Event<CheckImageRequest> event) {
    LOGGER.info("Received event: {}", event);
    CheckImageRequest request = event.getData();
    CloudContext cloudContext = request.getCloudContext();
    try {
        CloudConnector connector = cloudPlatformConnectors.get(request.getCloudContext().getPlatformVariant());
        AuthenticatedContext auth = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
        Image image = request.getImage();
        CloudStack stack = request.getStack();
        ImageStatusResult progress = connector.setup().checkImageStatus(auth, stack, image);
        CheckImageResult imageResult = new CheckImageResult(request, progress.getImageStatus(), progress.getStatusProgressValue());
        request.getResult().onNext(imageResult);
        LOGGER.info("Provision setup finished for {}", cloudContext);
    } catch (RuntimeException e) {
        CheckImageResult failure = new CheckImageResult(e, request, ImageStatus.CREATE_FAILED);
        request.getResult().onNext(failure);
    }
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) CloudContext(com.sequenceiq.cloudbreak.cloud.context.CloudContext) CheckImageResult(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult) AuthenticatedContext(com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext) Image(com.sequenceiq.cloudbreak.cloud.model.Image) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) CheckImageRequest(com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest) ImageStatusResult(com.sequenceiq.cloudbreak.common.type.ImageStatusResult)

Example 19 with Image

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

the class StackToStackResponseConverter method convert.

@Override
public StackResponse convert(Stack source) {
    StackResponse stackJson = new StackResponse();
    try {
        Image image = imageService.getImage(source.getId());
        stackJson.setImage(getConversionService().convert(image, ImageJson.class));
    } catch (CloudbreakImageNotFoundException exc) {
        LOGGER.info(exc.getMessage());
    }
    stackJson.setName(source.getName());
    stackJson.setOwner(source.getOwner());
    stackJson.setAccount(source.getAccount());
    stackJson.setPublicInAccount(source.isPublicInAccount());
    stackJson.setStackAuthentication(conversionService.convert(source.getStackAuthentication(), StackAuthenticationResponse.class));
    stackJson.setId(source.getId());
    if (source.getCredential() == null) {
        stackJson.setCloudPlatform(null);
        stackJson.setCredentialId(null);
    } else {
        stackJson.setCloudPlatform(source.cloudPlatform());
        stackJson.setCredentialId(source.getCredential().getId());
        stackJson.setCredential(getConversionService().convert(source.getCredential(), CredentialResponse.class));
    }
    stackJson.setStatus(source.getStatus());
    stackJson.setStatusReason(source.getStatusReason());
    stackJson.setRegion(source.getRegion());
    stackJson.setAvailabilityZone(source.getAvailabilityZone());
    stackJson.setOnFailureAction(source.getOnFailureActionAction());
    List<InstanceGroupResponse> templateGroups = new ArrayList<>(convertInstanceGroups(source.getInstanceGroups()));
    stackJson.setInstanceGroups(templateGroups);
    if (source.getCluster() != null) {
        stackJson.setCluster(getConversionService().convert(source.getCluster(), ClusterResponse.class));
    } else {
        stackJson.setCluster(new ClusterResponse());
    }
    if (source.getFailurePolicy() != null) {
        stackJson.setFailurePolicy(getConversionService().convert(source.getFailurePolicy(), FailurePolicyResponse.class));
    }
    if (source.getNetwork() == null) {
        stackJson.setNetworkId(null);
    } else {
        stackJson.setNetworkId(source.getNetwork().getId());
        stackJson.setNetwork(getConversionService().convert(source.getNetwork(), NetworkResponse.class));
    }
    stackJson.setParameters(Maps.newHashMap(source.getParameters()));
    stackJson.setPlatformVariant(source.getPlatformVariant());
    if (source.getOrchestrator() != null) {
        stackJson.setOrchestrator(getConversionService().convert(source.getOrchestrator(), OrchestratorResponse.class));
    }
    stackJson.setCreated(source.getCreated());
    stackJson.setGatewayPort(source.getGatewayPort());
    stackJson.setCustomDomain(source.getCustomDomain());
    stackJson.setCustomHostname(source.getCustomHostname());
    stackJson.setClusterNameAsSubdomain(source.isClusterNameAsSubdomain());
    stackJson.setHostgroupNameAsHostname(source.isHostgroupNameAsHostname());
    addNodeCount(source, stackJson);
    putSubnetIdIntoResponse(source, stackJson);
    putVpcIdIntoResponse(source, stackJson);
    putS3RoleIntoResponse(source, stackJson);
    convertComponentConfig(stackJson, source);
    convertTags(stackJson, source.getTags());
    addFlexSubscription(stackJson, source);
    return stackJson;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ArrayList(java.util.ArrayList) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) CredentialResponse(com.sequenceiq.cloudbreak.api.model.CredentialResponse) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse) FailurePolicyResponse(com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse) ImageJson(com.sequenceiq.cloudbreak.api.model.ImageJson) NetworkResponse(com.sequenceiq.cloudbreak.api.model.NetworkResponse) StackAuthenticationResponse(com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse)

Example 20 with Image

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

the class StackToStackDetailsConverter method convertComponents.

private void convertComponents(StackDetails stackDetails, Stack stack) {
    Long stackId = stack.getId();
    CloudbreakDetails cloudbreakDetails = componentConfigProvider.getCloudbreakDetails(stackId);
    if (cloudbreakDetails != null) {
        stackDetails.setCloudbreakVersion(cloudbreakDetails.getVersion());
    }
    try {
        Image image = componentConfigProvider.getImage(stackId);
        stackDetails.setImageIdentifier(image.getImageName());
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.warn("Image not found! {}", e.getMessage());
    }
    AmbariRepo ambariRepo = componentConfigProvider.getAmbariRepo(stackId);
    if (ambariRepo != null) {
        stackDetails.setPrewarmedImage(ambariRepo.getPredefined());
        stackDetails.setAmbariVersion(ambariRepo.getVersion());
    } else {
        stackDetails.setPrewarmedImage(Boolean.FALSE);
    }
    StackRepoDetails stackRepoDetails = componentConfigProvider.getHDPRepo(stackId);
    if (stackRepoDetails != null) {
        stackDetails.setClusterType(stackRepoDetails.getStack().get(StackRepoDetails.REPO_ID_TAG));
        stackDetails.setClusterVersion(stackRepoDetails.getHdpVersion());
    }
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) Image(com.sequenceiq.cloudbreak.cloud.model.Image)

Aggregations

Image (com.sequenceiq.cloudbreak.cloud.model.Image)20 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)8 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)7 HashMap (java.util.HashMap)7 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)6 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)5 InstanceAuthentication (com.sequenceiq.cloudbreak.cloud.model.InstanceAuthentication)5 PortDefinition (com.sequenceiq.cloudbreak.cloud.model.PortDefinition)5 Security (com.sequenceiq.cloudbreak.cloud.model.Security)5 SecurityRule (com.sequenceiq.cloudbreak.cloud.model.SecurityRule)5 Volume (com.sequenceiq.cloudbreak.cloud.model.Volume)5 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)4 Group (com.sequenceiq.cloudbreak.cloud.model.Group)4 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)4 ArrayList (java.util.ArrayList)4 Before (org.junit.Before)4 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)3 CheckImageRequest (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageRequest)3 CheckImageResult (com.sequenceiq.cloudbreak.cloud.event.setup.CheckImageResult)3 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3