use of com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate in project cloudbreak by hortonworks.
the class InstanceMetaDataToCloudInstanceConverter method convert.
@Override
public CloudInstance convert(InstanceMetaData metaDataEnity) {
InstanceGroup group = metaDataEnity.getInstanceGroup();
Template template = metaDataEnity.getInstanceGroup().getTemplate();
StackAuthentication stackAuthentication = group.getStack().getStackAuthentication();
InstanceStatus status = getInstanceStatus(metaDataEnity);
InstanceTemplate instanceTemplate = stackToCloudStackConverter.buildInstanceTemplate(template, group.getGroupName(), metaDataEnity.getPrivateId(), status);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication(stackAuthentication.getPublicKey(), stackAuthentication.getPublicKeyId(), stackAuthentication.getLoginUserName());
Map<String, Object> params = new HashMap<>();
params.put(CloudInstance.SUBNET_ID, metaDataEnity.getSubnetId());
return new CloudInstance(metaDataEnity.getInstanceId(), instanceTemplate, instanceAuthentication, params);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate in project cloudbreak by hortonworks.
the class MockInstanceUtil method addInstance.
public void addInstance(Map<String, CloudVmMetaDataStatus> instanceMap, int numberOfAddedInstances) {
ServerAddressGenerator serverAddressGenerator = new ServerAddressGenerator(numberOfAddedInstances);
serverAddressGenerator.setFrom(instanceMap.size());
serverAddressGenerator.iterateOver((address, number) -> {
String instanceId = "instance-" + address;
InstanceTemplate instanceTemplate = new InstanceTemplate("medium", "group", Integer.toUnsignedLong(number), new ArrayList<>(), InstanceStatus.CREATED, null, 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, instanceTemplate, instanceAuthentication);
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.STARTED);
CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(address, mockServerAddress, sshPort, "MOCK");
CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
instanceMap.put(instanceId, cloudVmMetaDataStatus);
});
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate in project cloudbreak by hortonworks.
the class MockInstanceUtil method terminateInstance.
public void terminateInstance(Map<String, CloudVmMetaDataStatus> instanceMap, String instanceId) {
CloudVmMetaDataStatus vmMetaDataStatus = instanceMap.get(instanceId);
InstanceTemplate oldTemplate = vmMetaDataStatus.getCloudVmInstanceStatus().getCloudInstance().getTemplate();
InstanceTemplate newTemplate = new InstanceTemplate("medium", "group", oldTemplate.getPrivateId(), new ArrayList<>(), InstanceStatus.TERMINATED, null, 0L);
InstanceAuthentication instanceAuthentication = new InstanceAuthentication("sshkey", "", "cloudbreak");
CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, newTemplate, instanceAuthentication);
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.TERMINATED);
CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, vmMetaDataStatus.getMetaData());
instanceMap.put(instanceId, cloudVmMetaDataStatus);
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate in project cloudbreak by hortonworks.
the class OpenStackMetadataCollector method collect.
@Override
public List<CloudVmMetaDataStatus> collect(AuthenticatedContext authenticatedContext, List<CloudResource> resources, List<CloudInstance> vms) {
CloudResource resource = utils.getHeatResource(resources);
String stackName = utils.getStackName(authenticatedContext);
String heatStackId = resource.getName();
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);
Stack heatStack = client.heat().stacks().getDetails(stackName, heatStackId);
List<CloudVmMetaDataStatus> results = new ArrayList<>();
List<Map<String, Object>> outputs = heatStack.getOutputs();
for (Map<String, Object> map : outputs) {
String instanceUUID = (String) map.get("output_value");
if (!StringUtils.isEmpty(instanceUUID)) {
Server server = client.compute().servers().get(instanceUUID);
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;
}
use of com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate 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);
}
Aggregations