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());
}
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);
}
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);
}
}
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;
}
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());
}
}
Aggregations