use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class OpenStackInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
OSClient<?> osClient = openStackClient.createOSClient(ac);
for (CloudInstance vm : vms) {
Optional<Server> server = Optional.ofNullable(vm.getInstanceId()).map(iid -> osClient.compute().servers().get(iid));
if (server.isPresent()) {
statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server.get())));
} else {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
}
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus 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.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class OpenStackNativeInstanceConnector method check.
@Override
public List<CloudVmInstanceStatus> check(AuthenticatedContext ac, List<CloudInstance> vms) {
List<CloudVmInstanceStatus> statuses = new ArrayList<>();
OSClient<?> osClient = openStackClient.createOSClient(ac);
for (CloudInstance vm : vms) {
Server server = osClient.compute().servers().get(vm.getInstanceId());
if (server == null) {
statuses.add(new CloudVmInstanceStatus(vm, InstanceStatus.TERMINATED));
} else {
statuses.add(new CloudVmInstanceStatus(vm, NovaInstanceStatus.get(server)));
}
}
return statuses;
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class MockScalingTest method configMockServer.
@BeforeClass
@Parameters({ "mockPort", "sshPort", "desiredCount", "hostGroup" })
public void configMockServer(@Optional("9443") int mockPort, @Optional("2020") int sshPort, int desiredCount, String hostGroup) {
IntegrationTestContext itContext = getItContext();
String clusterName = itContext.getContextParam(CloudbreakV2Constants.STACK_NAME);
StackResponse response = getCloudbreakClient().stackV2Endpoint().getPrivate(clusterName, null);
java.util.Optional<InstanceGroupResponse> igg = response.getInstanceGroups().stream().filter(ig -> ig.getGroup().equals(hostGroup)).findFirst();
Map<String, CloudVmInstanceStatus> instanceMap = itContext.getContextParam(CloudbreakITContextConstants.MOCK_INSTANCE_MAP, Map.class);
ScalingMock scalingMock = (ScalingMock) applicationContext.getBean(ScalingMock.NAME, mockPort, sshPort, instanceMap);
scalingMock.addSPIEndpoints();
scalingMock.addMockEndpoints();
scalingMock.addAmbariMappings(clusterName);
itContext.putContextParam(CloudbreakV2Constants.MOCK_SERVER, scalingMock);
igg.ifPresent(ig -> {
int scalingAdjustment = desiredCount - ig.getNodeCount();
if (scalingAdjustment > 0) {
scalingMock.addInstance(scalingAdjustment);
}
});
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus in project cloudbreak by hortonworks.
the class MockServer method terminateInstance.
public static 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);
}
Aggregations